I want to plot the values of each month and the respective year in one line, so basically 34 lines in a plot to show how the values are changing for 34 years

3 ビュー (過去 30 日間)
clear all;clc;
data= load('north_x_y_lat_lon');
datacoord = reshape(data, 361,361,4);
lat = squeeze(datacoord(:,:,3));
long = squeeze(datacoord(:,:,4));
%m_proj('Azimuthal Equal-area');
m_proj('stereographic','lat',90,'long',30,'radius',22);
m_grid('xtick',12,'tickdir','out','ytick',[65 70 75 80 85 90],'linest','-');
m_coast('patch',[.7 .7 .7],'edgecolor','r');
m_elev('contour',[ ],'edgecolor',' ');
Uyear = [];
Vyear = [];
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;
idx = find(lat >= lat1 & lat <= lat2 & (long >= long1 | long <= long2));
U1= U(idx);
V1= V(idx);
Umean = [Umean, mean(mean(U1))];
Vmean = [Vmean, mean(mean(V1))];
end
Uyear = [Uyear;Umean];
Vyear = [Vyear;Vmean];
end
  4 件のコメント
Sophia
Sophia 2016 年 2 月 4 日
And i found your suggestion helpful, it actually saved 10.55 seconds, Thank you!
dpb
dpb 2016 年 2 月 4 日
idx = iswithin(lat,lat1,lat2) & !iswithin(long,long1,long2);
where iswithin is my "syntactic sugar" utility
function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);
that puts the clutter of the logic expressions below the main code. Often doing this will make writing the code initially much simpler but even more often it'll aid remarkably on down the road when either wanting to change something or remember what it was that did...
>>

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2016 年 2 月 4 日
As per the documentation of plot, when supplied by a matrix it plots the columns as individual curves. So if you want to plot the rows, just transpose:
plot(Uyear')

その他の回答 (1 件)

dpb
dpb 2016 年 2 月 4 日
編集済み: dpb 2016 年 2 月 4 日
"...Uyear is a matrix with dimensions 34*12, how can i plot each row of that matrix as a line in a line plot"
mo=[1:12]; % months in year vector
hL=plot(mo,Uyear.; % plot versus month
Matlab in general operates on column-major basis. Each column is considered an observation. But, plot, by documentation is a little more general in that it will match lengths of input vector to the size of array and orient appropriately.
From the help...
plot(X1,Y1,...,Xn,Yn) plots each vector Yn versus vector Xn on
the same axes. If one of ... Xn is a matrix and the other is a vector, it plots the vector versus the matrix row or column with a matching dimension to the vector.
That's a little hard to parse, but the net result is that given the vector of months and the array of values, the dimension other than length 12 will be the independent variable. (If you also had 12 years, it's not documented clearly but I presume it would use column-major order but in that instance I'd certainly orient that way to be sure.)

カテゴリ

Help Center および File ExchangeData Preprocessing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by