PCA Graph of Data Comes Up Blank

5 views (last 30 days)
Mike Zimmers
Mike Zimmers 2021年5月2日
评论: Mike Zimmers2021年5月2日
我正在从气候数据工具箱中运行示例代码,并且在绘制数据的原理组件的图表方面存在问题。当我运行代码时,它会导致空白图。数据是附加的文件。以下是我的代码。
Clc
关闭all
clearall
%%TS
文件名='data';
s = dir(fullfile(文件名,)'*。文本文件');
为了k = 1:numel(s)
fnm = fullfile(filename,S(k).name);
mtx1 = load(fnm);
mtx1 =归一化(mtx1);
mtx = reshape(mtx1,72,144);
ts {k} = mtx;
ts {k}(ts {k} == -1000)= nan;
结尾
ts_cat = cat(3,ts {:});
lat =(-90:2.5:90);
lon =(-180:2.5:180);
[Lon,Lat] = meshgrid(lon,lat);
数字
ts_cat = fillmissing(ts_cat,“线性”);
imagescn(lon,lat,mean(TS_cat,3))
axisxy
cmocean热的
xlabel'经度'
ylabel'纬度'
%%
[eof_maps,pc,expv] = eof(TS_cat);
%Plot the first mode:
数字
imagesc(lon,lat,eof_maps(:,:,1))
axisxyimage
cmocean('curl',,,,'枢'
标题“第一个EOF模式!”
t =长度(PC(1,:));
数字
%subublot(3,1,1)
情节(t,PC(1,:))
boxoff
axistight
ylabel'pc1'
标题“第一个主要组件”
How would I fix this?
提前致谢。

答案(1)

乍得·格林
乍得·格林 2021年5月2日
I think you're mixing and matching different ways of defining filenames. As a result, dir 无法找到您要寻找的文件。
当我运行您的代码时,这是空的:
s = dir(fullfile(文件名,)'*。文本文件');
最简单的解决方案是直接导航到所有.txt文件所在的文件夹,然后执行
S = dir('*。文本文件');
我能够通过手动编写此行中的文件名来解决所有这些问题:
米tx1 = load('data.txt');
但是,这当然只会加载您上传的单个示例文件。结果,PC仅包含一个条目,因为只有一个时间步长。
6条评论
Mike Zimmers
Mike Zimmers 2021年5月2日
我变了
ts {k}(ts {k} == -1000)= nan;
TA{k}(TA{k} <= 0) = NaN;
in the loop and this is the figure that is produced:

登录发表评论。

社区寻宝

在Matlab Central中找到宝藏,发现社区如何为您提供帮助!

Start Hunting!