Index in position 1 is invalid. Array indices must be positive integers or logical values.
Infos
This question is locked. Rouvrir pour modifier ou répondre.
Afficher commentaires plus anciens
I am trying to take raw data from a zip file and the raw data includes x,y,z coordinates of each pixel in addition to the grayscale value (a measure of brightness/darkness of each pixel with lower values indicating darker pixel). The end result show be a clear xray. Here is what I have so far, but when I get to the for loop, I get an error of "Index in position 1 is invalid. Array indices must be positive integers or logical values."
How do I fix this?
image_data = readmatrix('Chest_Xray_Raw_Data.txt');
x = data(:, 1);
y = data(:, 2);
z = data(:, 3);
grayscale_value = data(:, 4);
max_x = max(x);
max_y = max(y);
max_z = max(z);
max_grayscale = max(grayscale_value);
[max_y, max_x]
image_matrix = zeros(uint8(max_y), uint8(max_x));
for i = 1:length(grayscale_value)
image_matrix(y(i), x(i))= grayscale_value(i);
end
1 commentaire
Rena Berman
le 10 Juil 2024
(Answers Dev) Restored edit
Réponses (1)
Voss
le 20 Juin 2024
0 votes
At least one element of y is not a positive integer so can't be used as an index in image_matrix.
3 commentaires
Hayley Devine
le 20 Juin 2024
Walter Roberson
le 20 Juin 2024
for i = 1:length(grayscale_value)
if x(i) > 0 && x(i) == floor(x(i)) & y(i) > 0 && y(i) == floor(y(i))
image_matrix(y(i), x(i))= grayscale_value(i);
else
fprintf('Skipped image_matrix(%g, %g) = %g\n', x(i), y(i), grayscale_value(i));
else
end
Walter Roberson
le 20 Juin 2024
... My guess is that some y is zero. Possibly the coordinates are zero-based instead of 1 based.
This question is locked.
Catégories
En savoir plus sur Creating and Concatenating Matrices 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!