How to convert matrices of different sizes in a for loop into a single column vector?

조회 수: 1 (최근 30일)
A = imread('Ish.JPG');
A = im2single(squeeze(mean(A,3)));
A = im2double(A);
[pyrRef,pind] = buildLpyr(A,'auto');
nLevels = 7;
kernelx = [0.0, 0.0, 0.0; 0.5, 0.0, -0.5; 0.0, 0.0, 0.0];
kernely = [0.0, 0.5, 0.0; 0.0, 0.0, 0.0; 0.0, -0.5, 0.0];
for k = 1:nLevels
subband = pyrBand(pyrRef, pind, k);
rx(k) = conv2(subband(k),kernelx);
ry(k) = conv2(subband(k),kernely);
amp = sqrt(subband.^2 + rx(k).^2 + ry(k).^2);
Phase = acos(subband./amp);
end
Here, the value of "Phase" is a matrix with varying dimension at each iteration of 'k'. How do I save all the values in these k matrices into a single coloumn vector?
  댓글 수: 2
Jiri Hajek
Jiri Hajek 2022년 12월 5일
편집: Jiri Hajek 2022년 12월 5일
Hi, you can make column vector from a matrix by using linear indexing
columnVector = Array(:);
And if by "save all" you mean to concatenate these vectors, then its possible simply by using brackets:
concatenatedVectors = [firstVector; secondVector];
Anisia Anil
Anisia Anil 2022년 12월 5일
by "save all" I meant, I want to save all k number of matrices into a sigle coloumn vector.

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

답변 (3개)

Jan
Jan 2022년 12월 5일
...
PhaseC = cell(1, nLevels);
for k = 1:nLevels
...
PhaseC{k} = acos(subband./amp);
end
Phase = cat(2, PhaseC{:}); % Maybe cat(1, ...

MFK
MFK 2023년 1월 16일
for k = 1:nLevels
...
Phase = acos(subband./amp);
re_shaped_Phas{k,1}=reshape(Phase,1,[]);
end

Bruno Luong
Bruno Luong 2023년 1월 16일
...
PhaseC = cell(1, nLevels);
for k = 1:nLevels
...
Phase = acos(subband./amp);
PhaseC{k} = Phase(:);
end
Phase = cat(1, PhaseC{:});

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by