问题描述
这是我在Matlab中的代码:如何获取所有保存的5张图像的所有值?此代码仅返回最后一张图片!我尝试使用IM(l),但它给了我一个错误:In an assignment A(I) = B, the number of elements in B and I must be the same.
This is my code in Matlab: How could I get all values of all 5 images saved? This code only returns the last image! I tried using IM(l) but it gives me an error: In an assignment A(I) = B, the number of elements in B and I must be the same.
Amount_measurements = 5;
IM=zeros(2097152,1);
l=1;
for l=(1:Amount_measurements)
if l < 9
%index = double(0)+double(0)+double(l+1);
index = strcat(num2str(double(0)),num2str(double(0)),num2str(double(l+1)));
elseif l < 99
index = double(0)+double(l+1);
else
index = double(l+1);
end
file_name1='trial.nii.gz';
%disp(file_name1);
jesu=load_nii(file_name1);
[x,y,z] = meshgrid(1:256,1:256,1:256);
[lx,ly,lz] = meshgrid(1:2:256,1:2:256,1:2:256);
newImage = interp3(x,y,z,jesu.img,lx,ly,lz);
IM= newImage(:);
end
我希望将值newImage(:)存储为IM1=newImage(:) IM2=newImage(:) IM3=newImage(:) IM4=newImage(:)
,依此类推...我该如何处理?
I want the values newImage(:) to be stored as IM1=newImage(:) IM2=newImage(:) IM3=newImage(:) IM4=newImage(:)
so on... How could I go about with it?
推荐答案
由于您提到想要变长版本的IM1=newImage(:) IM2=newImage(:) IM3=newImage(:) IM4=newImage(:)
,因此您正在寻找一个单元格数组.试试
Since you mentioned wanting a variable-length version of IM1=newImage(:) IM2=newImage(:) IM3=newImage(:) IM4=newImage(:)
, you're looking for a cell array. Try
IM{l} = newImage;
代替
IM(l) = newImage(:);
重要的区别是使用花括号而不是括号.如果要整形为向量,请使用newImage(:)
的右侧;如果要将其保留为矩阵,请使用newImage
.
The important difference is the use of braces rather than parentheses. Use a right-hand side ofnewImage(:)
if you want to reshape into a vector, just newImage
if you want to preserve it as a matrix.
这篇关于在分配A(I)= B中,B和I中的元素数必须相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!