error solved

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 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{:};

Share on social media

//