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

1 view (last 30 days)
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.

Answers (1)

KSSV
KSSV on 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 Comments

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!