MATLAB Answers

Accessing value in a cell

3 views (last 30 days)
jinang patel
jinang patel on 1 Dec 2019
Edited: Stephan on 1 Dec 2019
Hi,
I am trying to access value of a cell
>> a={'1,65,4,5'}
a =
1×1 cell array
{'1,65,4,5'}
>> a(2)
Index exceeds the number of array elements (1).
>> a{2}
Index exceeds array bounds.
Thanks
Jinang

  3 Comments

Stephen Cobeldick
Stephen Cobeldick on 1 Dec 2019
Look at what MATLAB is telling you:
a =
1×1 cell array
How many cells does your cell array have? (hint: one)
What do you expect to occur when you try to access a non-existent cell?
Disregarding your buggy indexing, what is the expected output?:
  • the character ','
  • the characters '65'
  • the number 65
  • something else...
jinang patel
jinang patel on 1 Dec 2019
Hi Stephen,
expected output - number 65. The problem is that I have data from a file which has a={'1,65,4,5'}, I understand removing the quotes will solve it but I cant change the file that generates the data. It is a single cell, is there a way to convert it to 1x4 array?
Stephan
Stephan on 1 Dec 2019
See my edited answer

Sign in to comment.

Accepted Answer

Stephan
Stephan on 1 Dec 2019
Edited: Stephan on 1 Dec 2019
Edited because of the comments:
a = {'1,65,4,5'}
b = str2num(a{:})
b(2)

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.