Subscripted assignment dimension mismatch.

I am trying to store the string in to one array in if else state ment. i get this error
Subscripted assignment dimension mismatch.
Error in connect (line 68) blob(i)='rectangle';

 Réponse acceptée

Bruno Pop-Stefanov
Bruno Pop-Stefanov le 20 Jan 2014

3 votes

This error means that you are trying to assign to an element of vector blob (size 1x1) a vector a size 1x9. That happens because in MATLAB, a string is a vector of characters: 'rectangle' is a vector of size 1x9, but blob(i) has size 1x1.
Are you trying to store strings of various sizes in the variable blob? What do you want to do when storing strings in a vector?

4 commentaires

saravanakumar D
saravanakumar D le 20 Jan 2014
yes i am trying to store various sizes of string in blob array
In that case, you should use a cell array . Cell arrays can store different sizes and types of data. They are more flexible that the traditional array.
Cell arrays are used very similarly to regular arrays. The difference is in how you access data: with curvy brackets {} instead of [] and ().
In your code, I would simply replace blob(i) by blob{i}.
You can read more here: Cell Arrays of Strings.
saravanakumar D
saravanakumar D le 20 Jan 2014
but i get this error
Cell contents assignment to a non-cell array object.
Error in connect (line 68) blob{i}='Rectangle';
Do you use blob somewhere else? Do you mind showing your code where you use blob?

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by