Unable to perform assignment because the left and right sides have a different number of elements in cell array

1 view (last 30 days)
Hello everybody,
Currently I have a bidimensional cell array which size is 200 * 2. I'm trying to append an element to the last position in some moment of my program, but however I'm unable to do so because I have this error "Unable to perform assignment because the left and right sides have a different number of elements".
I'm trying to append the data with this command: app.quizImages(end + 1) = {app.currentImageId, app.currentImagePath};
Where app.quizImages is the cell array, app.currentImageId is a number and app.currentImagePath is a string.
When I display the cell array this is the content that i'm getting (I have not putted everything since the size is 200 * 2)
{[ 1]} {'1.jpg' }
{[ 2]} {'10.jpg' }
{[ 3]} {'11.jpg' }
{[ 4]} {'12.jpg' }
{[ 5]} {'120.jpg'}
{[ 6]} {'121.jpg'}
And when I display the content I want to append this is what I'm getting
{[64]} {'21.jpg'}
Do you see any error in what I'm doing? I don't understand what I'm doing wrong and I have tried to fix it a long time already
Thank you!

Accepted Answer

Rashed Mohammed
Rashed Mohammed on 19 Mar 2021
Hi Marcos,
Since you want to append two items - app.currentImageId and app.currentImagePath to the end of cell array, you should be specifying the entire row instead of just a single cell. Below is the code to resolve your issue
app.quizImages(end+1,:) = {app.currentImageId, app.currentImagePath};
Hope this helps.

More Answers (0)

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!