Allocating values in 1d matrix

1 次查看(过去 30 天)
B = p * ones(327,245,2, uint8); can i do it with a loop?

采纳的回答

Image Analyst
Image Analyst 2017-12-6
No need for for loops, especially ones that don't work. Simply use ones:
B = p * ones(327,245,2, 'uint8');
  1 个评论
Image Analyst
Image Analyst 2017-12-6
Try this:
p=uint8(0);
for L = 3 : -1 : 1
for row = 327 : -1 : 1
for col = 245 : -1 : 1
B(row, col, L)=p;
end
end
end
It's a very inefficient way of doing it. I reverse the indexes to try to make it more efficient though. You should NOT want to do it this way.

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by