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!