How to extract a certain row from a struct based on a specific column name?

조회 수: 21 (최근 30일)
Hello!
I want to get the row with the DisplayName 'vfzg_w' based on the name, not the number of the field!
After that I want to work with the field Data of this specific row, is that possible?
Thanks for your advice!

채택된 답변

源樹 上林
源樹 上林 2020년 8월 13일
たぶんこう
data(data.DisplayName == 'vfzg_w', :)
  댓글 수: 2
Maytheewat
Maytheewat 2024년 12월 27일
This gives the following error
Error using ==
Too many input arguments.
Do you have any tips?
DGM
DGM 2024년 12월 27일
You don't have a scalar struct, so the LHS of the test is a CSL. You shouldn't be testing chars using == anyway. Use strcmp() or something.
% say i have a nonscalar struct
inpict = imread('cameraman.tif');
mask = inpict == 220;
S = regionprops(mask,'area')
S = 12x1 struct array with fields:
Area
% the only field is _numeric_ and _integer-valued_,
% so == makes sense here. it doesn't for char, or float.
% without the concatenation [], the LHS of this comparison
% is a comma-separated list -- i.e. multiple arguments
S2 = S([S.Area] == 2)
S2 = 2x1 struct array with fields:
Area

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by