将多个文件中的数据附加到 matlab 数组
您好,我需要您帮助将从许多文件中读取的所有数据附加到矩阵中。我已经制作了以下脚本,
path='C:\Users\Kostas\Documents\MATLAB\';
filefolder=strcat(path,'MSL*.txt');
files=dir(filefolder);
k=0;
for i=1:length(files)
filename=strcat(path,files(i).name);
%load the filename and create vectors of height (Z),
%lat and lon
newData=importdata(filename,'\t', 1);
vars = fieldnames(newData);
for j = 1:length(vars)
assignin('base', vars{j}, newData.(vars{j}));
end
timeas=data(:,1);
lat=data(:,2);
lon=data(:,3);
Z=data(:,4);
% daten=(timeas/24)+doy;
k=k+1;
%append data to matrix Teff_series
Teff_series(k,:)= [timeas lat lon Z];
end
当我运行此脚本时收到的错误消息是
??? Subscripted assignment dimension mismatch.
Error in ==> te at 31
Teff_series(k,:)= [lat lon Z];
提前感谢
Hello i need you help to append all the data i read from many files into a matrix. I have made the following script
path='C:\Users\Kostas\Documents\MATLAB\';
filefolder=strcat(path,'MSL*.txt');
files=dir(filefolder);
k=0;
for i=1:length(files)
filename=strcat(path,files(i).name);
%load the filename and create vectors of height (Z),
%lat and lon
newData=importdata(filename,'\t', 1);
vars = fieldnames(newData);
for j = 1:length(vars)
assignin('base', vars{j}, newData.(vars{j}));
end
timeas=data(:,1);
lat=data(:,2);
lon=data(:,3);
Z=data(:,4);
% daten=(timeas/24)+doy;
k=k+1;
%append data to matrix Teff_series
Teff_series(k,:)= [timeas lat lon Z];
end
the error message i get when i run this script is
??? Subscripted assignment dimension mismatch.
Error in ==> te at 31
Teff_series(k,:)= [lat lon Z];
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
让我举个例子:
如果我使用这些示例数据文件:
file1.dat
file2.dat
我得到以下结果:
Let me give an example:
If I use these sample data files:
file1.dat
file2.dat
I get the following results:
该错误表明等号表达式的左侧 - 在本例中:
Teff_series(k, :) 的
大小与右侧的大小不同:
调试此问题的一种方法是执行命令:
然后重新运行脚本。它将在引发错误的位置停止调试器,然后您可以找出大小差异。
希望这有帮助。
The error indicates that the left hand side of the equal expression - in this case:
Teff_series(k, :)
is of a different size than the right hand side:
One way to debug this issue is execute the command:
and then re-run your script. It will stop the debugger at the point where the error is thrown and then you can figure out the difference in sizes.
Hope this helps.