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