I am trying to do a scatter plot, with the x-axis occupying a range of 5 to 15 in steps of 0.25 and the y-axis occupying 41 random data for 20 days.
clc
clear
x = 5:0.25:15;
y = rand(41,20);
How can i achieve a scatter plot on MATLAB, whereby the x-range is applicable to all the 20 columns?
Did you possibly want a scatter plot with connected lines so that you could identify the different datasets? Here I used the same for-loop approach and holding the plot using hold on
. In the line plot(t,y(:,n),'.-');
the term '.-'
is used to indicate to plot the data with connected lines and dots at the data points. As the comment above indicated for a random dataset doing a best fit polynomial will not reveal very useful information if not any at all.
clf;
Start_Time = 5;
End_Time = 15;
Time_Interval = 0.25;
t = (Start_Time: Time_Interval: End_Time);
y = rand(41,20);
for n = 1:20
plot(t,y(:,n),'.-');
hold on
end
Legend_Labels = "Data 1";
for Dataset_Index = 2: size(y,2)
Legend_Labels = [Legend_Labels "Data "+num2str(Dataset_Index)];
end
Current_Figure = gcf;
Current_Figure.Position = [50 50 1000 400];
title("Plotting Random Data with Respect to Time");
legend(Legend_Labels,'Location','EastOutside','Orientation','vertical');
xlabel("Time (s)"); ylabel("Value");
Ran using MATLAB R2019b
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.