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

1 次查看(过去 30 天)
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

采纳的回答

David K.
David K. 2019-7-17
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by