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
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.