I have the following function:
function rgbMap = thresholdFunction(x)
rArray=zeros(size(numel(x)));
gArray=zeros(size(numel(x)));
bArray=zeros(size(numel(x)));
rArray(x>110 & x<=152) = 255;
gArray(x<=110) = 255;
bArray(x>152) = 255;
rgbMap = cat(3,rArray,gArray,bArray);
end
Which then gives the error message: 'Dimensions being concatenated are not consistent'
The function is designed to apply thresholds to a grayscale image which is the input 'x', and give a colormap of the different value selections 'rgbMap'.
The reason I'm using a function instead of applying the thresholds directly to the image, is because it's part of a batch processing code, and so 'x' would end up being more than one image being put through a 'for' loop.
I am fairly new to Matlab so if I'm doing something ridiculously stupid, feel free to point it out!

 採用された回答

Geoff Hayes
Geoff Hayes 2017 年 4 月 26 日
編集済み: Geoff Hayes 2017 年 4 月 26 日

0 投票

Andrew - look at the line
rArray=zeros(size(numel(x)));
numel returns the number of elements in x so this could be (for example) 42 which is a 1x1 scalar. Finding the size of this scalar will be
>> size(42)
ans =
1 1
and so all of your arrays will be 1x1. Just remove the numel from each of your array initializations so that the arrays are of the same dimension/size as the two-dimensional x.
Note that the error is occurring because while each of your arrays begin as 1x1 arrays, their updates with
rArray(x>110 & x<=152) = 255;
% etc.
will not guarantee that each of the three has the same dimension (even if they did, this is not the answer you want) and so you end up trying to concatenate three matrices of different dimensions.

1 件のコメント

Andrew McLean
Andrew McLean 2017 年 4 月 26 日
Knew it would be something like that, thanks for the answer

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2017 年 4 月 26 日

編集済み:

2017 年 4 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by