Array indices must positive or integers because I have decimals in mymatrixes
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello I have a one column data D which consist of double and decimal numbers and what to compute it using this code below
K = 1;
croppedz = D(1:end-mod(end, 2*K), :);
result = zeros(size(croppedz, 1) / 2 / K, size(croppedz, 2));
for col = 1:size(croppedz, 2)
result(:, col) = sum(reshape(sort(croppedz(1:2:end, col)), K, []), 1) ./ sum(reshape(sort(croppedz(2:2:end, col)), K, []), 1); %sort even/odd rows, reshape each into a Kx? matrix, sum across rows and divide the two sums
end
a = result;
I am getting the error
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in kmean (line 18)
result(:, col) = sum(reshape(sort(croppedz(1:2:end, col)), K, []), 1) ./ sum(reshape(sort(croppedz(2:2:end, col)), K, []), 1); %sort even/odd rows, reshape each into a Kx? matrix, sum across rows and divide the two sums
Can someone help me
Tino
1 Kommentar
Antworten (1)
Guillaume
am 30 Mai 2019
The actual indexing (of croppedz) in line 18 cannot produce an Array indices must be positive integers or logical values error. The only possible reason you can get this error is therefore if you've shadowed any of the functions used on that line by a variable, thereby changing a function call into an indexing of the variable with the same name.
My bet would be that you have a variable called sum. The other possible culprits would be sort or reshape.
Never call a variable sum (or mean, max, min, all, var, std, image, etc. the other commonly shadowed functions). You will inevitably run into this sort of problems.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!