Final struct result not showing
Afficher commentaires plus anciens
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.
Réponses (1)
Matt J
le 12 Oct 2017
0 votes
You need to return struct_C from the function.
Catégories
En savoir plus sur Structures dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!