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
2017-10-12
0 个投票
You need to return struct_C from the function.
类别
在 帮助中心 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!