# include all rows matrix in []

5 views (last 30 days)
piero on 5 Jun 2023
Commented: Walter Roberson on 5 Jun 2023
>> size(z)
ans =
5668 73
BB=[z(:,1),z(:,2),z(:,3)....z(:,73]
i need in [] include all rows z
how can i do it?
##### 2 CommentsShow 1 older commentHide 1 older comment
piero on 5 Jun 2023
Edited: piero on 5 Jun 2023
ok..i tried to transfer my problem to a wrong example..I post my main problem hoping to make me understand with few examples
Sis is a struct
>> size(Sis)
ans =
1 73
I want to add field Matrix (z)
size(z)
ans =
5668 73
[Sis.h]=deal(z) I can synthesize it with this code
for i=1:length(Sis)
Sis(i).New=F(:,i);
end
(but i want to avoid cicle for)

Walter Roberson on 5 Jun 2023
zc = num2cell(z,1); %1 --> preserve first dimension
[Sis.h] = zc{:}; %or [Sis.h] = deal(zc{:});

Paul on 5 Jun 2023
Edited: Paul on 5 Jun 2023
One way ....
Create example data
Sis.a = 1;
Sis = repmat(Sis,73,1);
z = rand(5668,73);
The code
[Sis.z] = cell2struct(num2cell(z,1),'z',1).z;
Verify
isequal([Sis.z],z)
ans = logical
1
Walter Roberson on 5 Jun 2023
Sis.a = 1;
Sis = repmat(Sis,73,1);
z = rand(5668,73);
[Sis.z] = struct('z', num2cell(z,1)).z;
isequal([Sis.z],z)
ans = logical
1