code that randomly changes columns in matrix throws error
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have a matrix
This matrix consists of four rows. Some numbers are integers and some are decimals. I want to print a code on this matrix, but it gives an error like this:
Error using randperm
Size inputs must be integers.
Error in deneme (line 49)
new_idx = randperm(size(D,2)/2)*2-[1; 0];
>>
My code is :
new_idx = randperm(size(D,2)/2)*2-[1; 0];
rassalnew= D(:,new_idx(:))
What can I do to fix this problem?
Thank for help
D matrix:
1 2 3 4
510.090000000000 26.4600000000000 22.3400000000000 188.300000000000
510.090000000000 26.4600000000000 22.3400000000000 169.680000000000
510.090000000000 26.4600000000000 22.3400000000000 188.300000000000
0 Commenti
Risposta accettata
Voss
il 23 Mar 2022
Modificato: Voss
il 23 Mar 2022
It seems to be working for that matrix D:
D = [ ...
1 2 3 4
510.090000000000 26.4600000000000 22.3400000000000 188.300000000000
510.090000000000 26.4600000000000 22.3400000000000 169.680000000000
510.090000000000 26.4600000000000 22.3400000000000 188.300000000000];
new_idx = randperm(size(D,2)/2)*2-[1; 0];
rassalnew= D(:,new_idx(:))
But you will get that error if D has an odd number of columns:
D = [ ...
0 1 2 3 4
300 510.090000000000 26.4600000000000 22.3400000000000 188.300000000000
400 510.090000000000 26.4600000000000 22.3400000000000 169.680000000000
200 510.090000000000 26.4600000000000 22.3400000000000 188.300000000000];
new_idx = randperm(size(D,2)/2)*2-[1; 0];
rassalnew= D(:,new_idx(:))
7 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Elementary Math in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!