appending an empty list

조회 수: 68 (최근 30일)
Eli Borodach
Eli Borodach 2015년 10월 21일
댓글: Robert 2015년 11월 5일
Hello all,
my code:
list_rats = [];
append(list_rats, Cell.rat);
when Cell.rat is a string. it throws me:
Error using append (line 39) Wrong number of input arguments for obsolete matrix-based syntax.
What should I do?
Thanks in advance
  댓글 수: 2
Jan
Jan 2015년 10월 21일
What is the function "append"? Does this appear using MuPad? See: http://www.mathworks.com/help/symbolic/mupad_ref/append.html
Eli Borodach
Eli Borodach 2015년 10월 22일
what is mupad? shlould I do include?

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

답변 (1개)

Robert
Robert 2015년 10월 21일
The behavior of append is specific to the data types input to it. For the basic types, you are probably better off using
list_rats = [];
a_new_list = [list_rats, Cell.rat];
% or
other_list = [list_rats; Cell.rat];
Also, if you indent your code (two spaces will do) when you type a question, answer, or comment, it will appear in a formatted code block as above.
  댓글 수: 2
Eli Borodach
Eli Borodach 2015년 10월 22일
I have allready tried it. The problem is that I allways add string at length of 16 characters and than when I add string in length of 17 characters it writes:
Error using vertcat
CAT arguments dimensions are not consistent.
Robert
Robert 2015년 11월 5일
You can append strings horizontally regardless of their length, i.e.
>> ['Hello,', ' ', 'World!']
ans =
Hello, World!
But because MATLAB arrays cannot be ragged, vertical concatenation of varying-length strings will produce an error.
>> ['Hello,'; ' '; 'World!']
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
If you are trying to collect a list of strings without combining them into one string, you should try cell arrays.
>> {'Hello', ',', ' ', 'World!'}
ans =
'Hello' ',' ' ' 'World!'
>> {'Hello'; ','; ' '; 'World!'}
ans =
'Hello'
','
' '
'World!'
>> {'Hello', ','; ' ', 'World!'}
ans =
'Hello' ','
' ' 'World!'
Use docsearch cell-arrays to learn more.

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by