Final struct result not showing

Hi,
I have the following code in `matlab`:
function test
for i=1:5
struct_C.(sprintf('C%d',i)) = 0
end
Now, when I run the function, I get the following:
>> test
struct_C =
C1: 0
struct_C =
C1: 0
C2: 0
struct_C =
C1: 0
C2: 0
C3: 0
struct_C =
C1: 0
C2: 0
C3: 0
C4: 0
struct_C =
C1: 0
C2: 0
C3: 0
C4: 0
C5: 0
But, I only want the following result:
struct_C =
C1: 0
C2: 0
C3: 0
C4: 0
C5: 0
So, when I type the following I get an error as shown (when I expected that I will get the final result of struct_C:
>> struct_C
??? Undefined function or variable 'struct_C'.
How can I solve this issue?
Thanks.

답변 (1개)

Matt J
Matt J 2017년 10월 12일

0 개 추천

You need to return struct_C from the function.

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

태그

질문:

2013년 2월 12일

답변:

2017년 10월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by