Add matrix to structure column without using for loop?

Is it possible to add a matrix to a column of a structure without using a for loop? For example, I have a structure with three fields

A.name
A.grade
A.attendance

now A.attendanceexpects a 1x5 matrix. If I have a 5x5 matrix, can I insert it into 5 rows of structure A? sort of

A(1:5).attendance = B

where B is a 5x5 matrix

+4
source share
2 answers

If yours is Bactually a 5-element array of cells, where each element is a 1 by 5 matrix (in fact, each element can contain anything), then

[A.attendance] = B{:}

. 5 5 B :

B_cell = mat2cell(B, ones(size(B,1),1),size(B,2))

temp deal:

[A.attendance] = deal(mat2cell(B, ones(size(B,1),1),size(B,1)))
+6

B ,

C = mat2cell(B, ones(size(B,1),1), size(B,2))

[A(1:size(B,2)).attendance] = C{:};
+6

Source: https://habr.com/ru/post/1615236/


All Articles