I need helpt with a for loop to pick numbers from a vector and put them in an existing non square in the order shown in the figure below (hop it makes sense). It starts at the dot and then follow the arrow. the resulting matrix should be as the one in the blackbackgrownd figure.
Sorry if this has been asked before <3 .
Thank you.

댓글 수: 6

James Tursa
James Tursa 2020년 11월 18일
Is this just for the specific problem you show (in which case you can simply use explicit indexing since the problem is small enough)? Or is there really a bigger problem you are trying to solve?
BiaoZhun
BiaoZhun 2020년 11월 18일
Hello James, thanks for replying.
The actual problem is a vector of size118668x1 to be put in a matrix of size 9889x12 so becase of the amount of data i need a for loop :S
James Tursa
James Tursa 2020년 11월 18일
Well, you don't necessarily need a for-loop. We just need to know the explicit indexing rule for your large vector.
BiaoZhun
BiaoZhun 2020년 11월 18일
The indexing patter should be as the same way as in the figure with the arrows, for which I hope the figure makes sense.
James Tursa
James Tursa 2020년 11월 18일
Start with 3 and increment by 3's, then start with 2 and increment by 3's, then start with 1 and increment by 3's?
BiaoZhun
BiaoZhun 2020년 11월 18일
yes, but it has to start one after the other, starts with 3(lets say n) and increments by 3's and then goes through the whole vector and then starts 2(n-1) an incremebts by 3's then goes through the whole vector agian, and then starts at 1(n-2) and increments by 3's. Hope this makes a better idea of the problem.

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

답변 (1개)

Stephen23
Stephen23 2020년 11월 18일

0 개 추천

"... so becase of the amount of data i need a for loop"
I doubt that using a loop would be a good approach.
V = 1:12;
R = 3;
M = flipud(reshape(V,R,[]))
M = 3×4
3 6 9 12 2 5 8 11 1 4 7 10
Your larger vector:
V = rand(118668,1);
R = 9889;
M = flipud(reshape(V,R,[]));
size(M)
ans = 1×2
9889 12

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2020년 11월 18일

답변:

2020년 11월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by