How to correct for 'Undefined function 'eq' for input arguments of type 'cell'' error message

8 ビュー (過去 30 日間)
Chameleon17
Chameleon17 2015 年 8 月 7 日
コメント済み: Chameleon17 2015 年 8 月 12 日
Hi,
I have a simple bit of code and keep getting an error message,
>>
for Area = 1:652
if Area == out(:,1)
DateofB = out(:,2)
LocationSquare(Area) = DateofB
end
end
Undefined function 'eq' for input arguments of type 'cell'.
I've tried using curled braces instead in my if statement but that doesn't work.
I've also tried using an isequal term instead too but it doesn't like that either.
Am I going about this in the wrong way?
Thanks for any help, advice, direction that can be spared.
  6 件のコメント
Chameleon17
Chameleon17 2015 年 8 月 11 日
編集済み: Walter Roberson 2015 年 8 月 11 日
Hi,
I would like it to be true for any.
Essentially, I have a 652 locations overall, numbered 1 - 652.
In my 'out' data I have two columns/vectors, the first has some of the numbered locations and the second has a date. Each location appearing only once in this file. I would like to file the date in column two for each location in the 'out' data into it's corresponding zero space in 'LocationSquare'.
Chameleon17
Chameleon17 2015 年 8 月 11 日
out =
[ 38] '09-Jul-2003'
[102] '21-May-2003'
[114] '18-Jun-2003'
[124] '27-May-2003'

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

回答 (2 件)

Matt J
Matt J 2015 年 8 月 7 日
I've tried using curled braces instead in my if statement but that doesn't work.
See what you get when you do the following,
>> A={1,2,3};
>> if A{1}==1, disp 'Hello World', end
Hello World
>> if A==1, disp 'Hello World', end
Undefined operator '==' for input arguments of type 'cell'.

Walter Roberson
Walter Roberson 2015 年 8 月 11 日
indices = cell2mat(out(:,1));
LocationSquare(indices) = out(indices,2);
No loop.
Note: this relies upon out(:,1) always being valid and unique.
  4 件のコメント
Chameleon17
Chameleon17 2015 年 8 月 12 日
Ah I see. Okay now my problem is
'Index exceeds matrix dimensions.
Error in FIRST_B (line 39) LocationSquare(indices) = out(indices,2);'
I'm assuming that this is because for each year my 'out' is a variable length depending on how many stations reported activity, and I am trying to file this into LocationSquare which is a 652 zero space. Am I right in thinking this is the problem? Perhaps I should try to file column one of the out before adding in the date information.
Chameleon17
Chameleon17 2015 年 8 月 12 日
This is quite annoying, I have pulled the data I require I just can't seem to manage to save it the way I want to...

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

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by