First calculating then looping with multiple figures
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi all
I am trying to combine some matrices, all with the same dimensions but different names. More specifically the quantities I am trying to assess have the same name of variable but a different timestep indicating their recorded time (e.g. Windv_y_20040501_180000)
I usually have used, when i first time started to analyse them, which give me a moving figure in matlab
[a1 a2 a3]=size(Windv_y_20040501_180000);
v10_profile=reshape(Windv_y_20040501_180000,a1,a2*a3);
for a=1:a3
imagesc(V10(:,:,a))
title('wind profile m/s V_1_0'),colorbar
drawnow;
pause(0.2);
end
Although this does not satisfy the next thing i want to achieve which is to combine two quantities and then have a figure(subplot) with the new combined re-calculated matrices in a separate plot
The files i normally use have this kind of structure, a constant name of variable but different endings.
Windv_y_20040501_180000
Windv_y_20040501_210000
Windv_x_20040501_180000
Windv_x_20040501_210000
Assuming that i want to automate a process for example, adding the corresponding matrices and then plot them
m1= Windv_x_20040501_180000 + Windv_y_20040501_180000
m2= Windv_x_20040501_210000 + Windv_y_20040501_210000
figure
subplot(2,1,1),image(m1)
subplot(2,1,2),image(m2)
Any suggestion would be welcome
thank you
4 commentaires
Jon Boerner
le 20 Oct 2014
I am still not quite sure what your whole workflow is, but going on what George suggested, you could keep the variables in a larger structure so that their names are maintained. For example:
mydata.Windv_x_20040501_180000 = Windv_x_20040501_180000;
mydata.Windv_y_20040501_180000 = Windv_y_20040501_180000;
>> fields = fieldnames(mydata)
ans =
'Windv_x_20040501_180000'
'Windv_y_20040501_180000'
And then using a loop:
for i=1:length(fields)
m = mydata.(fields{i});
% Plotting code...
end
You could do some more complicated logic to pull out fields with the same timestep and add them together or something like that using the field names as well.
Réponses (1)
Geoff Hayes
le 17 Oct 2014
You could create a cell array of n elements and so still keep the data sets distinct. If you are reading from n files then it would be something like
windVData = cell(n,2);
for k=1:n
% read x and y data from file
% some code here
% save to cell array
windVData(k,1) = xData;
windVData(k,2) = yData;
end
You could even save the file name in a third column of the array (if you wish).
Then you could iterate over this cell array and produce your subplots
figure;
n = size(windVData,1);
for k=1:n
% create a single column of n subplots
h = subplot(n,1,k);
% add the two vectors (assumed to be of the same dimension)
m1= windVData{k,1} + windVData{k,2};
% display the data
image(m1,'Parent',h);
end
Not really clear if you wish to use image or plot instead.
3 commentaires
Geoff Hayes
le 17 Oct 2014
Right - the two columns in the cell array correspond to the x and y data for a specific time step. The above just gives a general idea of what you can do (since you haven't shown how you load/read the different variables or time steps).
Though I'm not sure what you are hinting at with your assignment of i, as 20041231_180000 cannot be used as an index into m or suffixed onto Windv_y_.
As for plotting, is your data the wind velocity in the x direction and wind velocity in the y direction? What does the 300x300 mean? What does image show you when you add the two together? Since you haven't described what this data represents, I can't provide any (good) suggestions on how it should be displayed.
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!