incorrect or unexpected brackets

[newx, newy] = ind2sub([nrow, ncol], candidates(whichleast));
next = [next;(end,:)+{newx, newy}];
get error unexpected brackets

1 件のコメント

Stephen23
Stephen23 2017 年 2 月 7 日
need use MATLAB syntax

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

回答 (2 件)

Guillaume
Guillaume 2017 年 2 月 7 日
編集済み: Guillaume 2017 年 2 月 7 日

2 投票

Well, yes, the (end, :) can only work as indexing so should follow the name of a variable but comes after a ;.
On top of that, even if that didn't produce an error, you'd have the error that you try to add a cell array to something. + (addition) is not defined for cell arrays.
All in all, I've no idea what that 2nd line is supposed to do.

4 件のコメント

Ken
Ken 2017 年 2 月 7 日
I have 4 cells around a cell in question arranged in a cross. I want to put these 4 cells (their x,y coordinates) in an array called next.
Image Analyst
Image Analyst 2017 年 2 月 7 日
Why use cells at all? Why complicate your life? It sounds like you can use just normal, simple, numerical arrays. Why not do that?
Guillaume
Guillaume 2017 年 2 月 7 日
編集済み: Guillaume 2017 年 2 月 7 日
Assuming the cell in question has coordinates x, y, then
next = [x-1, y;
x, y+1;
x+1, y;
x, y-1];
would do what you want, if I understood correctly.
Note: I missed at first, that it appears that you're confusing x, y and row, column. Traditionally, x is the horizontal coordinates which would correspond to column, and y the vertical up which would correspond to row (or better height - row). So your ind2sub call should probably read:
[newy, newx] = ind2sub([nrow, ncol], candidates(whichleast)); %note the inversion: [y,x] not [x,y]
Ken
Ken 2017 年 2 月 13 日
Tried this - still get same error

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

Greg Heath
Greg Heath 2017 年 2 月 7 日

1 投票

I don't think
a. Square brackets are allowed on the RHS
b. Round brackets are allowed on the LHS
Hope this helps.
Thank you for formally accepting my answer
Greg

2 件のコメント

Stephen23
Stephen23 2017 年 2 月 7 日
"I don't think"
"a. Square brackets are allowed on the RHS"
a = [1,2];
"b. Round brackets are allowed on the LHS"
a(2) = 3;
Ken
Ken 2017 年 2 月 13 日
Get same error with: [newy, newx] = ind2sub([nrow, ncol], candidates(whichleast));

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

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

タグ

質問済み:

Ken
2017 年 2 月 7 日

コメント済み:

Ken
2017 年 2 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by