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

3 views (last 30 days)
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

Accepted Answer

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

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!