Info

This question is locked. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Index in position 1 is invalid. Array indices must be positive integers or logical values.

1 Ansicht (letzte 30 Tage)
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

Antworten (1)

Voss
Voss am 20 Jun. 2024
At least one element of y is not a positive integer so can't be used as an index in image_matrix.
  3 Kommentare
Walter Roberson
Walter Roberson am 20 Jun. 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
Walter Roberson am 20 Jun. 2024
... My guess is that some y is zero. Possibly the coordinates are zero-based instead of 1 based.

This question is locked.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by