How do I set up a function to split up a randomly generated vector into an "if,else" statements to resize it in equal portions of 1, 2, or 3 rows
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Tyler Young
am 12 Feb. 2020
Beantwortet: JESUS DAVID ARIZA ROYETH
am 12 Feb. 2020
array/vector = [1 2 3 4 5 6 7 8 9 10 11 12];
% but assuming I dont know the inputs to break up manually
% and as different possible answers I want...
output1 = [1,2,3,4,5,6,7,8,9,10,11,12]
output2 = [1,2,3,4,5,6]
[7,8,9,10,11,12]
output3 = [1,2,3,4]
[5,6,7,8]
[9,10,11,12]
0 Kommentare
Akzeptierte Antwort
JESUS DAVID ARIZA ROYETH
am 12 Feb. 2020
clc
array = [1 2 3 4 5 6 7 8 9 10 11 12];%1:12 do the same
s=1:numel(array);
fac = s(rem(numel(array),s)==0);
allpos=arrayfun(@(x) reshape(array,[],x)',fac,'UniformOutput',false);
allpos{:}
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Whos 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!