Index exceeds the number of array elements (0).
Afficher commentaires plus anciens
The code makes a new vector of values in the second column depending on the value 1-4 in the first column, for each iteration. outt is just for testing, in reality outt would contain different values in column 2 each time.
I would like it to work for all these scenarios:
outt = [1,100;2,200;3,300;4,400];
outt = [1,100;2,200;3,300];
outt = [1,100;2,200;3,300];
outt = [1,100];
but it only works for this scenario currently:
outt = [1,100;2,200;3,300;4,400];
here is the code:
%dessa ska vara utanför för att inte skriva över
statV_F = []
statV_A = []
statV_B = []
statV_D = []
outt = [1,100;2,200;3,300;4,400]
kolumn1 = outt(:,1)
%hitta om det finns 1-4:
no1 = find(1 == kolumn1);
no2 = find(2 == kolumn1);
no3 = find(3 == kolumn1);
no4 = find(4 == kolumn1);
%plocka ut raderna:
NO1 = outt(no1,:);
NO2 = outt(no2,:);
NO3 = outt(no3,:);
NO4 = outt(no4,:);
%göra vektorer som uppdaterar varje itertion:
statV_F = [statV_F NO3(2)]
statV_A = [statV_A NO3(2)]
statV_B = [statV_B NO3(2)]
statV_D = [statV_D NO4(2)]
3 commentaires
David Hill
le 23 Nov 2020
If you would give a typical input and the expected output, there should be a much easier way of doing what you want.
Chameleon
le 23 Nov 2020
Chameleon
le 23 Nov 2020
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!