Figure box does not show data when using plot(x,y)

3 Ansichten (letzte 30 Tage)
Zachary Smith
Zachary Smith am 17 Jul. 2019
Beantwortet: David K. am 17 Jul. 2019
When I run this script a figure box appears, but no lines appear. When I change plot(x,y) to scatter(x,y) the data appears correctly. Why won't plot(x,y) plot the data as a line? I am trying to plot the average pixel value of an image over time in two separate figures.
clear all
data = importdata('BSPB_09_DIC1.mat');
figure
for i = 1:102
y = mean2(data.data_dic_save.strains(i).plot_exx_ref_formatted(87:151,83:151));
x = i*4;
plot(x,y), hold on
end
figure
for i = 1:102
y = mean2(data.data_dic_save.strains(i).plot_eyy_ref_formatted(87:151,83:151));
x = i*4;
plot(x,y), hold on
end

Akzeptierte Antwort

David K.
David K. am 17 Jul. 2019
The reason is that you are trying to create a plot with a single data point multiple times. So each time you plot there are not two points for the plot function to connect.
A simple change is to make y and x y(i) and x(i) then plot outside the for loops.
With Matlab you can probably throw out the for loops altogether with matrices:
figure
i = 1:102;
y = mean2(data.data_dic_save.strains(i).plot_exx_ref_formatted(87:151,83:151));
x = i*4;
plot(x,y)

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by