Importing excel data to Matlab.

I am importing a data set from an Excel file into MATLAB to plot it and ID max, min and period. The code is working fine but MATLAB is reading the data as the row number, and not as the values inside each cell. For example, instead of my period being 12 sec (as it should be) it is 60, because one peak is in row 61 and the next in row 121. I hope that makes sense.

3 件のコメント

jonas
jonas 2018 年 9 月 2 日
Can you attach the file and briefly explain what your desired output is?
Ricardo Whitaker
Ricardo Whitaker 2018 年 9 月 2 日
編集済み: Walter Roberson 2018 年 9 月 2 日
%My code is right below.
X = xlsread('Loop Calculation','A2:A302');
Y = xlsread('Loop Calculation','B2:B302');
TF1 = islocalmin(Y,'MinProminence',0.1);
MinTime = find(TF1);
Period = mean(diff(MinTime));
plot(X,Y,X(TF1),Y(TF1),'or');
xlabel('Time (s)');
ylabel('Pressure (inH2O)');
title('Time vs. Pressure');
Ricardo Whitaker
Ricardo Whitaker 2018 年 9 月 2 日
Dear Jonas, As you can see in the EXCEL file, I have values for a certain pressure and time and my output is giving me the correct answer, however as the row position of the cell, and not its values. You know?

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

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 9 月 2 日

1 投票

Your X values appear to be in fractions of days. To convert to seconds:
X = xlsread('Loop Calculation','A2:A302') * (24 * 60 * 60)

3 件のコメント

Ricardo Whitaker
Ricardo Whitaker 2018 年 9 月 2 日
If you look at the Workspace, my MaxTime shows the respective row in which the peak occur, but not exactly the time value. On top of that, I would like to have the respective pressure at that time, meaning the peak value. Could you help me with that? I appreciate your answer.
Walter Roberson
Walter Roberson 2018 年 9 月 2 日
X(MaxTime)
Y(MaxTime)
Ricardo Whitaker
Ricardo Whitaker 2018 年 9 月 3 日
Works great. Thank you so much for the help.

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

質問済み:

2018 年 9 月 2 日

コメント済み:

2018 年 9 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by