two identical cell arrays treat my char inputs differently - any idea?

1 回表示 (過去 30 日間)
Claudia
Claudia 2012 年 11 月 5 日
|Hi
I read a lot about strings and inverted commas but I could not find the answer to my problem.
Believe me or not, I have two cell arrays which handle strings different.
Here, an extreme, but real example.
>> AA {1,1} = '''''''xyz''''''' and I get as answer >> AA {1,1} ans = '''xyz'''
>> BB {1,1} = '''''''xyz''''''' and I get as answer >> BB {1,1} ans = '''xyz'''
So far, that's fine.
BUT in the variables view I have
AA row 1, column 1 '''''''xyz''''''' (seven)
BB row 1, column 1 '''xyz''' (three)
The problem is that I cannot access them in the same way and I have NO idea why my inputs get treated differently.
Any ideas?
Thanks so much!
Claudia

採用された回答

Matthew Eicholtz
Matthew Eicholtz 2012 年 11 月 5 日
The only way I was able to reproduce your results was to initialize the AA cell array with size greater than (1,1). For example,
AA = cell(2);
AA {1,1} = '''''''xyz'''''''
BB {1,1} = '''''''xyz'''''''
Then, in the Variable Editor, it looks like you described (7 quotes on AA cell). However, the string stored in the cell array is still the same.
>> AA{1,1}
ans =
'''xyz'''
So in this case, the way it looks in the Variable Editor does not affect any processing you may want to do on the string.
  1 件のコメント
Claudia
Claudia 2012 年 11 月 8 日
Hi Matt,
thanks for your explanation.
However,I couldn't access the data in the same way and also interesting, sometimes I had for the same cell array sometimes 7, sometimes 3 quotes.
But I found a solution - if I load my dataset within a function, I always can access single data in the same way.
Cheers, Claudia

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2012 年 11 月 5 日
編集済み: Image Analyst 2012 年 11 月 5 日
I can't reproduce. I do (just copying and pasting your code):
AA {1,1} = '''''''xyz'''''''
BB {1,1} = '''''''xyz'''''''
and in the command window I get:
AA =
''''xyz''''
BB =
''''xyz''''
In the variables editor, it looks the same as the command window - 3 ' on each side, not 7.
  1 件のコメント
Claudia
Claudia 2012 年 11 月 8 日
Hi, thanks for the answer. That's the trouble with it. It doesn't happen always. Cheers, Claudia

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by