Concatenate 3-D matrix in a for loop

3 Ansichten (letzte 30 Tage)
Joana
Joana am 6 Mai 2021
Kommentiert: Stephen23 am 6 Mai 2021
Hi
I have 25 matrices of 3-D 150x66x1000. I need to concatenate them in a for loop to get an output of 3750x66x1000.
How can i do that.?
  1 Kommentar
Stephen23
Stephen23 am 6 Mai 2021
" I need to concatenate them in a for loop..."
Why do you need to use a FOR loop?
Using VERTCAT or CAT would be simpler and probably more efficient.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 6 Mai 2021
Bearbeitet: Stephen23 am 6 Mai 2021

Weitere Antworten (2)

KSSV
KSSV am 6 Mai 2021
A = rand(2,3,4) ;
B = rand(2,3,4) ;
C = cat(1,A,B)
  2 Kommentare
Joana
Joana am 6 Mai 2021
Thanks for the comment. But can you please help me with the loop thing.?
KSSV
KSSV am 6 Mai 2021
You have 25 matrices ... how they are named? How the data is?

Melden Sie sich an, um zu kommentieren.


Sambit Supriya Dash
Sambit Supriya Dash am 6 Mai 2021
With an example, I would like to answer this. Suppose, "a" is the given 3D Matrix
and "b" is the 2D matrix returns the concatenated "a"
a(:,:,1) = [1 2;3 4]; % a --> Given Tensor (3D Matrix) to be operated into matrix "b"
for i = 2:4
a(:,:,i) = a(:,:,i-1)+1; % Supposing elemental opeartion is incrementing element by 1
end
[x,y,z] = size(a); % Calculate the length of tensor in 3rd D
b = zeros(x,y*z);
for k = 1:z
for i = 1:x
for j = 1:y
b(i,j+2*(k-1)) = a(i,j,k); % Concatenating
end
end
end
% For Checking the Concatenation of 3D Elements
c = reshape(a,x,y*z);
if b == c
disp('CONCATENATION SUCCESSFUL')
disp(b)
else
disp('CONCATENATION FAILED')
end

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by