Plotting fixed X data against multiple Y data in matlab

5 ビュー (過去 30 日間)
Richard
Richard 2022 年 12 月 22 日
コメント済み: Richard 2022 年 12 月 23 日
Hello I need help with this.I am new to matlab.
I have an excel file with X DATA in first column and 44 Y DATA in adjecent columns and the average of all the ys in a last column.
I want to make a scatter plot for the fixed X data against all the 44 y data and also make a line graph of the X against the average of the Y all on a single graph.

採用された回答

Cameron
Cameron 2022 年 12 月 22 日
編集済み: Cameron 2022 年 12 月 23 日
Thank you for the clarification. There may be too many plots for the data to look nice, but the way I would do what you have described is as follows:
[file,path] = uigetfile('*.*'); %select the file
cd(path) %change directories
fileData = readmatrix(file); %read the file
xdata = fileData(:,1); %value for data in the first column. I assumed there were 44 data points for X
hold on %hold onto the plot so it doesn't overwrite it
for col = 2:size(fileData,2) - 1 %loop through all columns of data minus the y average
ydata = fileData(:,col); %value for data in the looped column.
plot(xdata,ydata,'o') %plot the first and looped column
end
y_avg = fileData(:,end); %last column of data
plot(xdata,y_avg,'-') %plot the x vs. the average y data
hold off %turn the hold off
  3 件のコメント
Cameron
Cameron 2022 年 12 月 23 日
I've updated it to fit your requirements. Try it now.
Richard
Richard 2022 年 12 月 23 日
This one worked perfectly. Thank you very much.

サインインしてコメントする。

その他の回答 (1 件)

Cameron
Cameron 2022 年 12 月 22 日
[file,path] = uigetfile('*.*'); %select the file
cd(path) %change directories
fileData = readmatrix(file); %read the file
xdata = fileData(:,1); %value for data in the first column. I assumed there were 44 data points for X
ydata = fileData(:,2); %value for data in the second column.
avgy = mean(ydata); %average of all the y data points
plot(xdata,ydata,'o') %plot the first and second column
hold on %hold onto the plot so it doesn't overwrite it
plot(xdata,ones(length(xdata),1)*avgy,'-') %plot the x vs. the average y data
hold off %turn the hold off
  1 件のコメント
Richard
Richard 2022 年 12 月 22 日
Thank you. This made the plot but not all the plots. Maybe my question wasn't clear.
I have say 250 data points in first column (x) and 250 data points in adjacent 44 columns(y) and 250 data points in the 46th column (y_average). I want to do a scatter plot for the X and the ys, and a line plot for the x and y_average.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeApp Building についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by