How to save Char from Structure into Array MATLAB

조회 수: 3 (최근 30일)
SH
SH 2023년 4월 5일
편집: Stephen23 2023년 4월 5일
Hello, I hope you are doing well. I have the following Dataset which is basically in Structure form.
I want to save the ClassName array of two rows and one column using for loop
I have tried the following code But the codes does not work. Can any body help me with that
load ('Dataset.mat')
for i =1:length(Dataset)
ClassificationResult=Dataset(i).ClassName
OverallResult(i)=ClassificationResult;
end

답변 (1개)

Stephen23
Stephen23 2023년 4월 5일
S = load('Dataset.mat');
D = S.Dataset
D = 1×2 struct array with fields:
ClassName Values
T = string({D.ClassName})
T = 1×2 string array
"Dog" "Cat"
  댓글 수: 4
SH
SH 2023년 4월 5일
@Stephen23 Dont want to convert it into string.
Use char and save it into array using loop
Stephen23
Stephen23 2023년 4월 5일
편집: Stephen23 2023년 4월 5일
"Dont want to convert it into string. Use char and save it into array using loop"
S = load('Dataset.mat');
D = S.Dataset
D = 1×2 struct array with fields:
ClassName Values
C = char(D.ClassName)
C = 2×3 char array
'Dog' 'Cat'
A string array is better. A loop is not required.

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

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by