Error using vertcat Dimensions of matrices being concatenated are not consistent.
1 view (last 30 days)
Show older comments
for y=1979:2012,
% open binary file for
% Polar Pathfinder Daily 25 km EASE-Grid Sea Ice Motion Vectors, Version 2
folderpath = 'C:\Users\SK\Documents\MATLAB\Mean_months\';
stryear = num2str(y);
filepath = fullfile(folderpath,stryear);
files = dir(fullfile(filepath,'\icemotion.mean.*.n.v02.bin') );
files = {files.name};
Umean = [];
Vmean = [];
for i=1:numel(files),
disp(files{i});
filename = fullfile(filepath,files{i});
fid = fopen(filename);
rawdata = fread(fid,[361, inf],'int16');
fclose(fid);
% reshape it into a [3x361x361] matrix
dd = reshape(rawdata,[3, 361, 361]);
% change 3d matrix to simple matrix, and divide by 10 to get cm/second
U = squeeze(dd(1,:,:)) ./ 10;
V = squeeze(dd(2,:,:)) ./ 10;
% Change the data values from cm/s to m/second by multiplying it with 1/100
U = U*1/100;
V = V*1/100;
%subset the region of interest
lat1 = 73;
lat2 = 83;
long1 = 150;
long2 = -170;
[i1,j1] = find(lat >= lat1 & lat <= lat2 & (long >= long1 | long <= long2));
U1= U(i1,j1);
V1= V(i1,j1);
Umean = [Umean, mean(mean(U1))];
Vmean = [Vmean, mean(mean(V1))];
end
Uyear = [Uyear; Umean];
Vyear = [Vyear; Vmean];
U2 = abs(Uyear);
V2 = abs(Vyear);
end
clf;
figure(1);
set(gca,'XLim',[0 13])
set(gca,'XTick',[1:1:12])
set(gca,'XTickLabel',['Jan';'Feb';'Mar';'Apr';'May';'June';'July';'Aug';'Sep';'Oct';'Nov';'Dec'])
hold all
plot(U2,'g')
xlabel('Month')
ylabel ('Ice motion(ms)')
title('Monthly Zonal-Meridional Ice Motion')
hold off
0 Comments
Accepted Answer
Walter Roberson
on 2 Feb 2016
You have
[i1,j1] = find(lat >= lat1 & lat <= lat2 & (long >= long1 | long <= long2));
U1= U(i1,j1);
V1= V(i1,j1);
This is incorrect. Unless there happened to be only one single result, i1 and j1 would be returned as vectors, with i1(K) corresponding to j1(K) for any given K. But when you use U(i1,j1) you are asking for all of the combinations, i1(K) with j1(J), a rectangular subsection rather than individual elements. Just like if you write U(2:3, 5:6) that is the same as U([2 3], [5 6]) which is a 2 x 2 subsection, not just the two values U(2,5), U(3, 6)
Your code does not show the definition of lat or long. If it is the same size as U and V then you should use the single output form of find for linear indices,
idx = find(lat >= lat1 & lat <= lat2 & (long >= long1 | long <= long2));
U1= U(idx);
V1= V(idx);
and if the lat and long are not the same size but somehow the indices will match anyhow, then
[i1,j1] = find(lat >= lat1 & lat <= lat2 & (long >= long1 | long <= long2));
idx = sub2ind(size(U), i1, j1);
U1 = U(idx);
V1 = V(idx);
0 Comments
More Answers (0)
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!