# Plotting signal of a region of interest

2 ビュー (過去 30 日間)
Dimitra Flouri 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:
SignalROI = zeros(1,1, size(dim,3));
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."

サインインしてコメントする。

### 回答 (1 件)

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 件のコメント表示非表示 3 件の古いコメント
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.

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!