How to I include a structure value in a title?

조회 수: 8 (최근 30일)
Lea Rossander
Lea Rossander 2013년 12월 10일
댓글: sixwwwwww 2013년 12월 10일
I want to create the following title:
"Title for plot where struct value mystruct.val1 is equal to 80."
using this line of code:
title(['Title for plot where struct value mystruct.val1 is equal to', num2str(mystruct.val1)])
'mystruct' is defined as follows:
mystruct=struct('val1',80);
Why does this give me the error: "Undefined variable "mystruct" or class"mystruct.val1"."
I checked that if I call mystruct.val1 in the matlab prompt I get the correct mystruct.val1=80.
Being quite new to the use of structs I may have misunderstood some simple idea, and I would be very grateful if someone could explain this to me - thanks in advance!

채택된 답변

sixwwwwww
sixwwwwww 2013년 12월 10일
mystruct=struct('val1',80);
title(['Title for plot where struct value mystruct.val1 is equal to ', num2str(mystruct.val1)])
It is working correctly. Have you defined your structure before using it?
  댓글 수: 2
Lea Rossander
Lea Rossander 2013년 12월 10일
I needed to call the file where my struct is defined inside the function, which I thought unnecessary - thank you!
sixwwwwww
sixwwwwww 2013년 12월 10일
you are welcome

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

추가 답변 (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