Creating a cell and allocation specific text

Hello,
My objective is to create an array cell like:
result = {'Intercept','X1','X2','X3',....'X41'}, in the 1st colum I got the word Intercept, and 2nd X1, 3rd X2, so on until reach X41 in the 42th colum
result = cell(1,42);
result{1,1} = 'Intercept';
result_aux = sprintfc('X%d', 1:41);
result{1,2:end} = result_aux; % Here i get the error
From the last code line i get this error message:
Expected one output from a curly brace or dot indexing expression, but there were 41 results.
What am I doing wrong?
Thanks

 채택된 답변

Alex Mcaulley
Alex Mcaulley 2019년 4월 9일

1 개 추천

result = cell(1,length(beta));
result{1} = {'Intercept'};
result(2:end) = sprintfc('X%d', 1:41);

추가 답변 (2개)

KSSV
KSSV 2019년 4월 9일

0 개 추천

result = cell(1,length(beta));
result{1,1} = {'Intercept'};
result_aux = sprintfc('X%d', 1:41);
legend{1,2:end} = legend_aux; % Here i get the error

댓글 수: 1

madhan ravi
madhan ravi 2019년 4월 9일
편집: madhan ravi 2019년 4월 9일
KSSV isn’t this the exact copy from the question?

댓글을 달려면 로그인하십시오.

Tiago Dias
Tiago Dias 2019년 4월 9일

0 개 추천

Instead of { } i used now ( ) and it works.
result(1,2:end) = result_aux(1,1:end);

댓글 수: 2

madhan ravi
madhan ravi 2019년 4월 9일
편집: madhan ravi 2019년 4월 9일
That’s exactly how Alex showed in his answer.
Tiago Dias
Tiago Dias 2019년 4월 9일
Yes, when i discovered by myself, i posted here the solution for someone that might need. and i accepted alex response

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2019년 4월 9일

댓글:

2019년 4월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by