My plot is empty...?
조회 수: 26 (최근 30일)
이전 댓글 표시
- PowerMat___410_1_50_1040_0.0074072_1_66.5059_186.8998_8_15_0_0_233_1_2_0_1_300_0.42732.mat
- PowerMat___410_1_50_1040_0.31826_1_53.7571_39.1524_8_15_0_0_231_1_2_0_1_300_0.66363.mat
- PowerMat___410_1_50_1040_0.011913_1_74.0395_0.0056209_8_15_0_0_233_1_2_0_1_300_0.93434.mat
- PowerMat___410_1_50_1040_0.01425_1_87.5579_0.047101_8_15_0_0_232_1_2_0_1_300_0.43689.mat
- PowerMat___410_1_50_1040_0.00045891_1_85.5167_0.0021192_8_15_0_0_231_1_2_0_1_300_0.84962.mat
- PowerMat___410_1_50_1040_0.16627_1_25.4669_0.017391_8_15_0_0_232_1_2_0_1_300_2.1587.mat
- PowerMat___410_1_50_1040_0.054629_1_18.9688_0.038009_8_15_0_0_231_1_2_0_1_300_1.2543.mat
- PowerMat___410_1_50_1040_0.10307_1_44.9841_25.8454_8_15_0_0_232_1_2_0_1_300_2.0398.mat
- PowerMat___410_1_50_1040_0.22413_1_82.2505_0.0057799_8_15_0_0_232_1_2_0_1_300_2.1464.mat
- PowerMat___410_1_50_1040_0.065439_1_13.5437_0.030313_8_15_1_0.75_231_1_2_0_1_300_0.32461.mat
- PowerMat___410_1_50_1040_0.38247_1_87.8745_164.1222_8_15_0_0_231_1_2_0_1_300_1.2475.mat
- PowerMat___410_1_50_1040_0.0083409_1_33.7002_40.718_8_15_0_0_233_1_2_0_1_300_1.8547.mat
- PowerMat___410_1_50_1040_0.00012471_1_45.9683_1.986_8_15_0_0_232_1_2_0_1_300_1.023.mat
- PowerMat___410_1_50_1040_0.0011733_1_8.8678_21.1738_8_15_1_0.75_231_1_2_0_1_300_0.050798.mat
- PowerMat___410_1_50_1040_0.076718_1_11.5103_0.42703_8_15_1_0.75_233_1_2_0_1_300_1.7001.mat
- PowerMat___410_1_50_1040_0.00011804_1_21.4698_0.6016_8_15_0_0_232_1_2_0_1_300_1.7036.mat
- PowerMat___410_1_50_1040_0.0091754_1_32.4289_0.014097_8_15_0_0_233_1_2_0_1_300_0.15957.mat
- PowerMat___410_1_50_1040_0.0060496_1_24.1705_0.3336_8_15_0_0_231_1_2_0_1_300_2.0191.mat
- PowerMat___410_1_50_1040_0.010573_1_96.8415_685.6558_8_15_0_0_233_1_2_0_1_300_1.6798.mat
- PowerMat___410_1_50_1040_0.00075624_1_78.7039_88.2412_8_15_0_0_233_1_2_0_1_300_2.2695.mat
- PowerMat___410_1_50_1040_0.072429_1_53.4358_166.9422_8_15_0_0_231_1_2_0_1_300_0.01891.mat
- PowerMat___410_1_50_1040_0.20923_1_60.5429_223.4521_8_15_0_0_231_1_2_0_1_300_1.9172.mat
- PowerMat___410_1_50_1040_0.046181_1_44.1507_0.0010016_8_15_0_0_231_1_2_0_1_300_0.71048.mat
- PowerMat___410_1_50_1040_0.0086132_1_25.5913_2.0147_8_15_0_0_232_1_2_0_1_300_0.10716.mat
- PowerMat___410_1_50_1040_0.00011933_1_78.0925_6.3371_8_15_0_0_232_1_2_0_1_300_1.7597.mat
- PowerMat___410_1_50_1040_0.038679_1_96.1697_998.1683_8_15_0_0_232_1_2_0_1_300_0.51716.mat
- PowerMat___410_1_50_1040_0.0071849_1_5.1938_0.94328_8_15_1_0.75_231_1_2_0_1_300_0.3145.mat
- PowerMat___410_1_50_1040_0.041631_1_56.9664_0.055645_8_15_0_0_233_1_2_0_1_300_1.2004.mat
- PowerMat___410_1_50_1040_0.001132_1_86.9482_0.0027513_8_15_0_0_232_1_2_0_1_300_1.7936.mat
- PowerMat___410_1_50_1040_0.0016904_1_89.736_84.6009_8_15_0_0_231_1_2_0_1_300_0.097987.mat
Hello. I am trying to create a plot containing data from multiple files. I have producecd a code that seems to be running (no errors come up when trying to run it). However, the plot is blank. The code will create a figure window and a plot with axes, titles and everything, but it does not display my data. I have left my code below, does someone spot any mistake or where I could have gone wrong?
%Find and sort files from directory
P = 'C:/Users.../' ; %Working directory (my directory, it is the correct one I have triple checked)
S = dir (fullfile (P , 'PowerMat_*.mat')) ; %All of the files have the same structure for the name. They are PowerMat_xx_xx_xx... .mat (xx are numbers, they are a pretty big list of different parameters that vary with each simulationseparated by _)... not sure this is the correct syntax to recall them?
S = natsortfiles (S) ; %Sort folders / file names into natural order
%Set conditions for plot
x = 15 : 1 : 50 ; %Array of z values on zmin_15 (from 15 to 50 in steps of 1) for x axis
n = 39 ; %Nº of column to read of the PowerMat (each column is a w value)
%Start plot
figure(1) ;
hold on ;
for k = 1 : numel (S)
fn = S(k).name ; % filename : used for legend
fn = strrep (fn , ' ' , ' ') ;% replace _ by space for better legend rendering
leg{k} = fn ; % store in cell array
% load data
F = fullfile (S(k).folder , S(k).name) ;
data = load (F) ; % is structure
names = fieldnames (data) ; % get fieldnames
y = data.(names{1}) ; % your data (assumed in first fieldname)
y = y (: , n) ; %Selecting column n on data
plot (x , y)
end
set (gca , 'YScale' , 'log') %Sets y axis to be logarithmic scale. Comment for linear scale
title ('title') ;
xlabel ('x label') ;
ylabel ('y label') ;
hold off
댓글 수: 2
Johan
2022년 7월 7일
You are plotting in log scale, have you checked that your data is positive ? It looks like Matlab plot nothing in log scale if you have less than 2 consecutive points and you are ploting lines.
x = linspace(1,10);
y = x-x(end-1);
y(5) = 10;
plot(x,y)
set(gca,'YScale','log')
plot(x,y,'*')
set(gca,'YScale','log')
답변 (3개)
Image Analyst
2022년 7월 7일
This should really be a FAQ since it's asked so often. You're probably plotting a single data point and you didn't call "hold on" so the next time it goes to call plot, it blows away the previously plotted point.
To fix, either put hold on
plot(x, y, 'b.', 'MarkerSize', 20);
grid on;
hold on;
or call plot after the loop and pass it the whole vectors.
If you have any more questions, then attach your data (mat files) and code to read it in with the paperclip icon after you read this:
댓글 수: 2
Image Analyst
2022년 7월 7일
Did you overlook the part where I said:
If you have any more questions, then attach your data (mat files) and code to read it in with the paperclip icon after you read this:
Torsten
2022년 7월 7일
Change
x = 15 : 1 : 50 ;
to
x = (15 : 1 : 50).' ;
댓글 수: 5
Image Analyst
2022년 7월 7일
You still haven't attached 'PowerMat_*.mat'. We'll check back later for it.
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


