Plotting signal of a region of interest

조회 수: 4 (최근 30일)
DM
DM 2021년 2월 5일
댓글: Steve Eddins 2021년 2월 5일
Hi,
I have 3D data [114,114,55] = [x, y , time]. I also have a binary mask with 0 background and 1s the pixels correspong to lung. I would like to plot the Signal versus time for the lung region.
I did the following:
dim=mask;
SignalROI = zeros(1,1, size(dim,3));
lung = lungdata.*mask;
for i=0, size(dim,3)
SignalROI(:,:,i) = mean(lung(:,:,i));
end
plot(SignalROI)
But I get the following error:
"Subscript indices must either be real positive integers or logicals."
Could you please help?

답변 (1개)

Steve Eddins
Steve Eddins 2021년 2월 5일
편집: Steve Eddins 2021년 2월 5일
A possible explanation is that you have a variable called "size" or "mean" in your workspace. For example, if you have a variable called "size" in your workspace, then size(dim,3) is an indexing expression into that variable rather than a call to the size function.
Here are a couple of other notes about the code:
  • The for-loop syntax is incorrect. Indexing should start at 1, and the syntax should be for i = 1:size(dim,3). (Starting the index at 0 would also produce the error message you received.)
  • mean(lung(:,:,i)) doesn't return a scalar. It returns a vector containing the mean of each column of lung(:,:,i). If you have R2018b or later, use this instead: mean(lung(:,:,i),'all'). Otherwise, use mean(mean(lung(:,:,i))).
  댓글 수: 4
DM
DM 2021년 2월 5일
Sorry I didn't noticed that. I corrected the code as you suggested but then I has another error:
"Error using plot
Data cannot have more than 2 dimensions."
SignalROI = zeros(1,1, 26);
lung = lungdata.*mask;
for i=1:26
SignalROI(:,:,i) = mean(mean(lung(:,:,i)));
end
plot(SignalROI)
So I wrote the above code like this:
SignalROI = zeros(26);
lung = lungdata.*mask;
for i=1:26
SignalROI(i) = mean(mean(lung(:,:,i)));
end
plot(SignalROI)
Is the above correct?
Steve Eddins
Steve Eddins 2021년 2월 5일
Almost. zeros(26) makes a 26x26 matrix. Use zeros(26,1) or zeros(1,26) instead, depending on whether you want a column or a row vector.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by