How to print value from Structure in MATLAB

조회 수: 59 (최근 30일)
Stephen john
Stephen john 2022년 7월 4일
편집: Image Analyst 2022년 7월 20일
Hello Everyone, I hope you are doing well, I have the following Structure which include Prediction and ValueStructure
I want to print the Value from ValueStructure
for Class 1 i have write the following Code.
pred2 = sprintf('Class1 Levels: %d\n Maximum Value of Class1:%d\n Minimum Value of Class1:%d\n',CombineOutput(1).PRFStructure.StagLevels,CombineOutput(1).PRFStructure.StaggMinimumValue,CombineOutput(1).PRFStructure.StaggMaximumValue);
But i am unable to print StagPRFValue. How can i print it.
For Class 2
pred1 = sprintf('Class 2 Levels: %d\n Maximum Value of Class 2:%d\n Minimum Value of Class 2:%d\n ',CombineOutput(2).PRFStructure.Levels,CombineOutput(2).PRFStructure.DSmaximum,CombineOutput(2).PRFStructure.DSminimum);
I want to print unique values of DSPRFValue and DS Length
How can i do that in Matlab

답변 (2개)

Jonas
Jonas 2022년 7월 4일
편집: Jonas 2022년 7월 4일
you can access the 4 doubles in the cell StagPRFValue by e.g.
CombineOutput(1).ValueStructure.StagPRFValue{1}
the other two values can be accessed with
CombineOutput(2).ValueStructure.DSPRFValue
and
CombineOutput(2).ValueStructure.DSlength
if you want the unique values of those vectors, use unique(CombineOutput(2).ValueStructure.DSlength)
  댓글 수: 6
Jonas
Jonas 2022년 7월 5일
why does it not work? i edited to previous comment to show, that the syntax is right.
Do you get an error, or did you want another output? please be more specific
Stephen john
Stephen john 2022년 7월 19일
@Jonas i am printing this value in the Textbox in app designer, basically it is not working in that

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


Image Analyst
Image Analyst 2022년 7월 19일
Assuming your sprintf worked to put the right string into pred, you can send pred to the text label component on the GUI like this
app.PredEditField.Value = pred; % Send pred string to the label on the GUI.
If you have any more questions, then attach your .mlapp code after you read this:
  댓글 수: 10
Stephen john
Stephen john 2022년 7월 20일
@Image Analyst and for Class 2 ValueStructure consists of two more variable which is DSPRFValue and and DSlength which should be printed you have not printed that.
in this dataset StagPRFValues have four values but they should not always four they should be changed How can i print that
Image Analyst
Image Analyst 2022년 7월 20일
편집: Image Analyst 2022년 7월 20일
I think you could have figured it out yourself knowing how sprintf() works, but anyway, here is what I got to handle a variable number of elements in the StagPRFValues vector.
s = load('StephenJohn.mat');
CombineOutput = s.CombineOutput;
for z = 1: numel(CombineOutput)
thisClass = char(CombineOutput(z).Prediction);
predictedPRI = sprintf('Cluster %1.0f Predicted PRI: "%s".\n',z, thisClass);
fprintf('For z = %d, %s\n', z, predictedPRI)
app.TextArea.Value = predictedPRI;
% Get the table from the structure. "ValueStructure" is a field of hte structure and it is a table-type variable.
tbl = CombineOutput(z).ValueStructure;
% Prepare the string.
if contains(thisClass, '1')
predictedPRI = sprintf('Class1 Levels: %d\n\n StagePRFValues: [', tbl.StagLevels);
StagPRFValues = tbl.StagPRFValue{1};
numValues = numel(StagPRFValues);
for k = 1 : numValues
predictedPRI = sprintf('%s%d ', predictedPRI, StagPRFValues(k));
end
predictedPRI = sprintf('%s]\n Maximum Value of Class1:%d\n Minimum Value of Class1:%d\n', ...
predictedPRI, ...
tbl.StaggMinimumValue, ...
tbl.StaggMaximumValue)
app.TextArea_3.Value = predictedPRI;
elseif contains(thisClass, '2')
predictedPRI = sprintf('Class 2 Levels: %d\n Maximum Value of Class 2:%d\n Minimum Value of Class 2:%d\n ', ...
tbl.Levels, ...
tbl.DSmaximum, ...
tbl.DSminimum)
app.TextArea_2.Value = predictedPRI;
end
end
I think you should be able to add any additional variables you want to print. If not, see sprintf. If you really can't figure it out based on how I wrote out the other variables, then write back. Otherwise, can you click "Accept this answer."?

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

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by