Solved – Scalar structure required for this assignment

In this article, you will learn how to solve Scalar structure required for this assignment error in Matlab. Let’s look at a code example that produces the…

The post Solved – Scalar structure required for this assignment appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Deven

In this article, you will learn how to solve Scalar structure required for this assignment error in Matlab.

Let’s look at a code example that produces the same error.

myStruct=repmat(struct('text1',0),10,1);
myarray = [1 2 3 4 5 6 7 8 9 10];
for j = 1:10 mystruct(j).text11 = myarray(j); end
mystruct.text11 = myarray

output

Scalar structure required for this assignment

In order to solve Scalar structure required for this assignment error in Matlab you need toallocate new data to the same field of each element of that structure like in the example below:

myStruct=repmat(struct('text1',0),10,1);
myarray = [1,2,3,4,5,6,7,8,9,10];
C = num2cell(myarray);
[myStruct.newfield] = C{:};

The post Solved – Scalar structure required for this assignment appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Deven


Print Share Comment Cite Upload Translate Updates
APA

Deven | Sciencx (2021-03-11T05:11:11+00:00) Solved – Scalar structure required for this assignment. Retrieved from https://www.scien.cx/2021/03/11/solved-scalar-structure-required-for-this-assignment/

MLA
" » Solved – Scalar structure required for this assignment." Deven | Sciencx - Thursday March 11, 2021, https://www.scien.cx/2021/03/11/solved-scalar-structure-required-for-this-assignment/
HARVARD
Deven | Sciencx Thursday March 11, 2021 » Solved – Scalar structure required for this assignment., viewed ,<https://www.scien.cx/2021/03/11/solved-scalar-structure-required-for-this-assignment/>
VANCOUVER
Deven | Sciencx - » Solved – Scalar structure required for this assignment. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/11/solved-scalar-structure-required-for-this-assignment/
CHICAGO
" » Solved – Scalar structure required for this assignment." Deven | Sciencx - Accessed . https://www.scien.cx/2021/03/11/solved-scalar-structure-required-for-this-assignment/
IEEE
" » Solved – Scalar structure required for this assignment." Deven | Sciencx [Online]. Available: https://www.scien.cx/2021/03/11/solved-scalar-structure-required-for-this-assignment/. [Accessed: ]
rf:citation
» Solved – Scalar structure required for this assignment | Deven | Sciencx | https://www.scien.cx/2021/03/11/solved-scalar-structure-required-for-this-assignment/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.