Azzera filtri
Azzera filtri

Info

This question is locked. Riaprila per modificarla o per rispondere.

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

17 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

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

This question is locked.

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by