필터 지우기
필터 지우기

include all rows matrix in []

조회 수: 4 (최근 30일)
piero
piero 2023년 6월 5일
댓글: Walter Roberson 2023년 6월 5일
>> 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
Paul
Paul 2023년 6월 5일
Are you sure the problem is stated correctly? As written, BB will be the same as z.
Here's a small example:
z = rand(2,3)
z = 2×3
0.0201 0.5622 0.2440 0.3879 0.1390 0.2752
BB = [z(:,1),z(:,2),z(:,3)]
BB = 2×3
0.0201 0.5622 0.2440 0.3879 0.1390 0.2752
piero
piero 2023년 6월 5일
편집: piero 2023년 6월 5일
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
Walter Roberson 2023년 6월 5일
zc = num2cell(z,1); %1 --> preserve first dimension
[Sis.h] = zc{:}; %or [Sis.h] = deal(zc{:});

추가 답변 (1개)

Paul
Paul 2023년 6월 5일
편집: Paul 2023년 6월 5일
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
  댓글 수: 1
Walter Roberson
Walter Roberson 2023년 6월 5일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by