Only producing one graph rather then range of graphs.
조회 수: 5 (최근 30일)
이전 댓글 표시
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')
댓글 수: 0
채택된 답변
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
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 Center 및 File Exchange에서 Printing and Saving에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!