Info

This question is locked. 请重新打开它进行编辑或回答。

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

1 次查看(过去 30 天)
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 个)

Voss
Voss 2024-6-20
At least one element of y is not a positive integer so can't be used as an index in image_matrix.
  3 个评论
Walter Roberson
Walter Roberson 2024-6-20
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

This question is locked.

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by