Finding the maximal value in a matrix, within a specific column, and show the value in the output.
1 回表示 (過去 30 日間)
古いコメントを表示
Hello, I have a matrix that I need to extract the maximal value of column D, which is the 4th column.
I use the following command
D=readtable('tempDataTrollhFlygpl.xlsx')
[~,x] = max(D(:,4));
B = D(x,:);
However, it does not work, and I get the error
Error using tabular/max
Applying the function 'max' to the variable 'Latitud_decimalgrader_' generated an error.
Error in untitled (line 2)
[~,x] = max(D(:,4));
Caused by:
Error using max
Invalid data type. First argument must be numeric or logical.
I should specify the rows after row 11 I think, but how that done?
I tried islocalmax instead, with plot command, but also this case didn't work.
A=readtable('tempDataTrollhFlygpl.xlsx')
plot(A(:,3:end), A(:,4:end))
xlabel('Temperature')
ylabel('Time')
TF1 = islocalmax(A,'FlatSelection','first');
Thanks
1 件のコメント
採用された回答
Voss
2024 年 2 月 14 日
編集済み: Voss
2024 年 2 月 14 日
D(:,4) is a table (consisting of one column - the 4th column of D), not a numeric array; that's what the error is trying to tell you.
To get the data out of the table, you can use the syntax D{:,4}. However, in this case, column 4 of your table is a cell array of character vectors, not a numeric array, so you'll get a similar error using that syntax. (Note the single quotes around the numbers in column 4 below, indicating character vectors.)
D=readtable('tempDataTrollhFlygpl.xlsx')
"I should specify the rows after row 11 I think, but how that done?"
Specify 'NumHeaderLines', 10 in your readtable call:
D=readtable('tempDataTrollhFlygpl.xlsx', 'NumHeaderLines', 10) % specifying 10 header lines
Now, you need to convert those character vectors to numbers, either by setting the appropriate import options before readtable is called, or after the fact by converting e.g. using str2double
val = str2double(D{:,4})
[~,x] = max(val)
B = D(x,:)
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!