Plotting signal of a region of interest
Afficher commentaires plus anciens
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?
Réponses (1)
Steve Eddins
le 5 Fév 2021
Modifié(e) : Steve Eddins
le 5 Fév 2021
0 votes
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 commentaires
Steve Eddins
le 5 Fév 2021
Dimitra, indexing should start at 1, not 0. I edited my answer above to show that.
DM
le 5 Fév 2021
Steve Eddins
le 5 Fév 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.
Catégories
En savoir plus sur Images dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!