필터 지우기
필터 지우기

find the max value in a struct

조회 수: 4 (최근 30일)
elisa ewin
elisa ewin 2017년 5월 12일
편집: Stephen23 2017년 5월 12일
Hi,
I have a struct (attached) and I want to find the max value of the second column in the field score. I have tried this code:
[val,idx] = max([GlobalScore.score])
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
but it gives an error, can you help me? thanks

채택된 답변

Stephen23
Stephen23 2017년 5월 12일
편집: Stephen23 2017년 5월 12일
Your basic concept of how to do this is okay, you just need to pay more attention to the details, such as the data sizes, and what data classes the data are. In this case you have some character and some numeric data, and they all have different number of rows (so concatenating horizontally would never work).
>> C = vertcat(GlobalScore.score);
>> M = str2double(C(:,1));
>> M(:,2) = vertcat(C{:,2});
>> max(M)
ans =
4.4333e+006 2.5831e-001
Notes:
  1. The first column of data is not numeric, but is stored as character vectors.
  2. Using a structure with just one field is not good program design. It would be simpler to use a cell array.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by