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 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sophia
el 3 de Feb. de 2016
Comentada: dpb
el 4 de Feb. de 2016
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 comentarios
dpb
el 4 de Feb. de 2016
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...
>>
Respuesta aceptada
Guillaume
el 4 de Feb. de 2016
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')
0 comentarios
Más respuestas (1)
dpb
el 4 de Feb. de 2016
Editada: dpb
el 4 de Feb. de 2016
"...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.)
Ver también
Categorías
Más información sobre Data Preprocessing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!