Effacer les filtres
Effacer les filtres

4x1 4 matrix conversion to 4x4 4 matrix

3 vues (au cours des 30 derniers jours)
dhlee
dhlee le 24 Août 2021
Commenté : dhlee le 26 Août 2021
I want to convert 4x1 4 matrix to 2x2 4 matrix as below.
How should I make script?
a=[0; 0; 0; 0]
b=[1; 2; 3; 4]
c=[5; 6; 7; 8]
d=[0; 0; 0; 0]
->
e1=[0 1; 5 0]
e2=[0 2; 6 0]
e3=[0 3; 7 0]
e4=[0 4; 8 0]
------ Please fix my code. Thank you~
close all;
clc;
clear all;
a=[0; 0; 0; 0]
b=[1; 2; 3; 4]
c=[5; 6; 7; 8]
d=[0; 0; 0; 0]
for k=1:4
e=[a(k,1) b(k,1);c(k,1) d(k,1)]
end

Réponse acceptée

Walter Roberson
Walter Roberson le 24 Août 2021
a=[0; 0; 0; 0]
b=[1; 2; 3; 4]
c=[5; 6; 7; 8]
d=[0; 0; 0; 0]
for k=1:4
e{k}=[a(k,1) b(k,1);c(k,1) d(k,1)]
end

Plus de réponses (1)

Chunru
Chunru le 24 Août 2021
a=[0; 0; 0; 0];
b=[1; 2; 3; 4];
c=[5; 6; 7; 8];
d=[0; 0; 0; 0];
eall =[a b c d];
for i = 1:4
e = reshape(eall(i,:), [2 2])'
end
e = 2×2
0 1 5 0
e = 2×2
0 2 6 0
e = 2×2
0 3 7 0
e = 2×2
0 4 8 0
%e1=[0 1; 5 0]
%e2=[0 2; 6 0]
%e3=[0 3; 7 0]
%e4=[0 4; 8 0]

Catégories

En savoir plus sur Data Types dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by