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