Assignment has more non-singleton rhs dimensions than non-singleton subscripts

조회 수: 3 (최근 30일)
Sophia
Sophia 2016년 3월 28일
댓글: Walter Roberson 2016년 4월 1일
% open binary file for
% Polar Pathfinder mean monthly 25 km EASE-Grid Sea Ice Motion Vectors, Version
folderpath = 'C:\Users\sk\Documents\MATLAB\nsidc0116_ice_motion_vector_v3\';
years = 1979:2014;
sid_allyears = zeros(361,361,12,36);
yearindex = 0;
for j = years;
disp(j);
yearindex = yearindex+1;
stryear = num2str(j);
filepath = fullfile(folderpath,stryear);
files = dir(fullfile(filepath,'\icemotion.grid.month.*.n.v3.bin') );
files = {files.name};
r_years = []; % (361,361,12)
d_years = []; % (361,361,12)
mm = 0 ;
for i=1:numel(files);
disp(files{i});
mm = mm+1;
filename = fullfile(filepath,files{i});
fid = fopen(filename);
rawdata = fread(fid,[361, inf],'int16');
fclose(fid);
% reshape it into a [3x361x361] matrix
tdata = reshape(rawdata,[3, 361, 361]);
% change 3d matrix to simple matrix, and divide by 10 to get cm/second
u = squeeze(tdata(1,:,:)./10.);
v = squeeze(tdata(2,:,:)./10.);
error = tdata(3,:,:)./10;
[TH,R] = cart2pol(v,u);
D = rad2deg(TH);
r_years(:,:,mm) = R;
d_years(:,:,mm) = D;
end
sid_allyears(:,:,:,yearindex) = r_years;
end

답변 (1개)

Walter Roberson
Walter Roberson 2016년 3월 28일
Your line
r_years(:,:,i) = R;
implies that r_years will be a 3D matrix with the third dimension being as large as the number of files.
Your line
sid_allyears(:,:,j) = r_years;
implies that r_years is a 2D matrix (since j is a scalar.)
This is a fundamental mismatch in expectation about what your r_years matrix is and what your output size should be. Should your third dimension of sid_allyears() be the year index, or should it be the file number index?
  댓글 수: 4
Sophia
Sophia 2016년 3월 29일
편집: Sophia 2016년 3월 29일
each year contains 12 files..To be honest i don't know how to use this subscript.. i am learning matlab through mathwork discussions, and what so ever i think can work in my case i am using that

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by