Only producing one graph rather then range of graphs.

조회 수: 5 (최근 30일)
muhammad choudhry
muhammad choudhry 2022년 7월 17일
댓글: Star Strider 2022년 7월 17일
Hi,
I am trying to produce 45 graphs using the code below but it only producing one graph. what am I doing wrong. I also would like to save the graphs by its folder name basically there are 45 folders with specific folder name holding the csv file from which the data is read and plotted. your Help would save a lot of time.
Code:
close all; clear all; clc;
P = 'F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_D\Data_PIV\6-VectorSatistics\PlotOverLine';
S = dir(fullfile(P,'Run*Profile*','Export*.csv'));
for k = 1:numel(S)
F = fullfile(S(k).folder,S(k).name);
M = readmatrix(F);
length=M(:,2);
U_x{k}=M(:,11);
U_y{k}=M(:,12);
U_m{k}=M(:,25);
plot (length,[U_x{k},U_y{k},U_m{k}],'-');
end
%Chart Representation
title('Velocities Across VFC (Below Outlet)');
xlabel('Distance(mm)');
ylabel('Velocities (m/s)');
legend('Velocities in x-direction','Velocities in y-direction','Resultant-Velocities')

채택된 답변

Star Strider
Star Strider 2022년 7월 17일
It appears that the last plot overplots all the previous plots. Perhaps adding a figure call will do what you want —
figure
plot (length,[U_x{k},U_y{k},U_m{k}],'-')
The rest of the code remians unchanged.
.
  댓글 수: 4
muhammad choudhry
muhammad choudhry 2022년 7월 17일
can we save them with the same name as folder in a different place ?
Star Strider
Star Strider 2022년 7월 17일
Save them with slightly different names, for example:
figure
plot (length,[U_x{k},U_y{k},U_m{k}],'-')
pfn = fullfile(P,sprintf('MyPlot_%03d.png', k));
saveas(gcf, pfn)
Change the string in the sprintf call to match the file name you want to save the figures with. This example saves each as .png files using the ‘k’ loop index to distinguish them, however that format is not the only option, and saving itt as .fig saves all the components of the figure, including the data, if that is desired. See the saveas documentation section on filename for details.
.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by