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

1 次查看(过去 30 天)
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.

回答(1 个)

KSSV
KSSV 2019-6-3
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 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by