random selection of a cell
Ältere Kommentare anzeigen
Hello,
I have a cell(matrix) of size 100*100.I need to scan each column and choose 4 consecutive random cells( (1*1)*4) for assigning values.Can anyone please help me with this?
Thanks in advance
Akzeptierte Antwort
Weitere Antworten (1)
Bruno Luong
am 22 Jul. 2020
A = zeros(100,100);
something = 1;
for c = 1:100
r = randi(97) + (0:3);
A(r,c) = something;
end
3 Kommentare
KK14
am 22 Jul. 2020
Bruno Luong
am 22 Jul. 2020
Bearbeitet: Bruno Luong
am 22 Jul. 2020
Replace "r = randi(97) ..." by
ncons = 4;
r = randi(size(A,1)-ncons+1)+(0:ncons-1)
You also specify 4 consecutive rows in your original question. Feel free if you want change 4 to something else.
KK14
am 22 Jul. 2020
Kategorien
Mehr zu Entering Commands finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!