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

1 次查看(过去 30 天)
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!

采纳的回答

Rashed Mohammed
Rashed Mohammed 2021-3-19
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by