Assigning Cell Arrays to Nested Structures within Structure array with Same Dimensions (Error: "Scalar structure required for this assignment")
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I currently have a structure containing a 2x1 structure array each containing a structure with one field:
struct.structArr(:).field1.field1_1
I have tried to assing values from a cellfun to 'field1_1' using the following code:
[struct.structArr.field1.field1_1] = outputOfCefllfun{:};
The 'structArr' is a 2x1 matrix of structures and the output of the cellfun is a 2x1 cell array each containing a matrix of doubles.
I receive the following error:
Scalar structure required for this assignment.
Is there any way of assigning these values without having to do another cellfun?
Any help would be appreciated, thank you.
0 commentaires
Réponses (1)
xi
le 26 Août 2019
I don't know how your struct is initialized. It should work.
%initialize
outputOfCefllfun{1,1}=magic(5);
outputOfCefllfun{2,1}=magic(5);
struct.structArr(1,1).field1=[];
struct.structArr(2,1).field1=[];
%assign
[struct.structArr.field1] = outputOfCefllfun{:};
2 commentaires
xi
le 26 Août 2019
Further nested structure is getting more complicated, but you can always use "for loop" to assign the values.
for i=1:2
struct.structArr(i).field1.field1_1=outputOfCellfun{i};
end
Voir également
Catégories
En savoir plus sur Structures dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!