How to format this Loop?

2 ビュー (過去 30 日間)
Sean St Cyr
Sean St Cyr 2020 年 11 月 11 日
コメント済み: Sean St Cyr 2020 年 11 月 11 日
So the code below is reading in an excel file and the one excel sheet "Data" has sets of numbers that need to be together (hence why i have the interval in the for loop going by 2) so that every 2 rows is an x and y value, however im having a hard time formatting it for x and y because i cant hardcode it. The Data may be differnt in terms of rows. can anyone help?
Information = readtable("Cooling Data.xlsx",'Sheet',"Information"); %Reads in the Information
Data = readmatrix('Cooling Data.xlsx','Sheet',"Data"); %Reads in the Data
choice = questdlg('What type of plot do you want to create?','Plot','Summary','Detail','Detail'); %Makes the User select an option
if strcmp(choice,'Summary')
for d = 1:2:height(Data)
x = Data(d,:);
y = Data(d,:);
plot(x,y,'*') %Plot data
xlim([0 10]) %Sets x axis from 0-10
ylim([0 100]) %Sets y axis from 0-100
xlabel('Time (t) [min]'); %X-axis label
ylabel('Temperature difference (T) [°C]'); %Y-axis label
title('Summary Plot'); %Title of graph
grid on %Turns grid on
end

採用された回答

Jon
Jon 2020 年 11 月 11 日
編集済み: Jon 2020 年 11 月 11 日
In your code above x and y are the same they are both assigned to Data(d,:) do you mean to have?
x = Data(d,:);
y = Data(d+1,:);
Also if you want to accumulate curves on your plot for each pair you will need to add
hold on
Somewhere in your loop, otherwise you will only see the last curve
  1 件のコメント
Sean St Cyr
Sean St Cyr 2020 年 11 月 11 日
Thats what i was looking for, thank you so much, haha such a miniscule error

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBar Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by