Filter löschen
Filter löschen

Could anyone help me how to solve the following issue with respect to the following code

1 Ansicht (letzte 30 Tage)
code:
a= [4.7908 5.0104 5.1329 5.3186 5.3094 5.3070 5.4452 5.5001;
0.0958 0.0994 0 0 0.1848 0.2020 0.1851 0.2146;
0.0848 0 0.1469 0.1859 0.1767 0.1854 0.1856 0.1648;
0 0 0 0 0 0 0 0;
0 0.0896 0.1619 0.1351 0 0 0 0;
0 0 0 0 0 0 0 0]
for i=1:size(a,2)
b=a(:,1:i)
iwant = reshape(b(randperm(numel(b))),size(b))
end
with respect to the code in for loop,
when the loop runs for the first time it takes the first column and reshape it and
when the loop runs for the second time it takes the first and second column and reshapes it.
But what i actually need is when the loop runs for the first time by taking the first column,reshape it ,should not be changed when the loop runs for the second time by taking the second column.
Could anyone please help me on it.

Antworten (1)

KSSV
KSSV am 3 Jun. 2019
a=[ 4.7908 5.0104 5.1329 5.3186 5.3094 5.3070 5.4452 5.5001;
0.0958 0.0994 0 0 0.1848 0.2020 0.1851 0.2146;
0.0848 0 0.1469 0.1859 0.1767 0.1854 0.1856 0.1648;
0 0 0 0 0 0 0 0;
0 0.0896 0.1619 0.1351 0 0 0 0;
0 0 0 0 0 0 0 0] ;
[m,n] = size(a) ;
b = a ;
for i = 1:m
idx = randperm(n) ;
b(i,:) = a(i,idx) ;
end
  5 Kommentare

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by