- 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))).
Plotting signal of a region of interest
1 view (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Steve Eddins
on 5 Feb 2021
Edited: Steve Eddins
on 5 Feb 2021
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:
4 Comments
Steve Eddins
on 5 Feb 2021
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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!