.append() equivalent in MATLAB
2,558 次查看(过去 30 天)
显示 更早的评论
Hi all,
I have a doubt regarding the function in MATLAB which will perform same function as performed by .append() in PYTHON. Do you have any function in mind which will use same activity of extending a list in MATLAB.
Thanks in advance!
0 个评论
采纳的回答
Stephan
2020-11-9
>> List = [1 2 3; 4 5 6]
List =
1 2 3
4 5 6
>> List = [List; 7 8 9]
List =
1 2 3
4 5 6
7 8 9
3 个评论
Saunok Chakrabarty
2021-4-22
Hi Stephan,
Is there a function that expands an array dynamically inside a loop, like append() in Python? Like it will keep adding elements based on a specified condition within the loop.
Regards,
Saunok
Cem Keske
2021-10-19
Hello,
You can use this directly to expand the array dynamically:
array = [array, other_array];
For example:
array = [];
for i = 1:10
if mod(i,2) == 0
array = [array, i]
end
end
I hope this helps,
Regards,
Cem
更多回答(1 个)
Amir Azadeh Ranjbar
2023-10-6
yes...
you can use end :
there are many way to do this :
examples :
ThemeCopy
x = [1,2,3,4,5] ;
y = [6,7,8] ;
Num_Add = size(y,2) ;
counter = 1 ;
while counter <= Num_Add
Last = size(x,2)+1 ;
x(1,Last) = y(1,counter) ;
counter = counter + 1;
end
disp(x)
1 2 3 4 5 6 7 8
also you can python in matlab very easy :
ThemeCopy
data = py.list([1,2,3,4]) ;
data.append(9)
double(data)
ans = 1×5
1 2 3 4 9
Another example that can be used to add rows to the table
ThemeCopy
data_mat = [1;2;3;4] ;
data = table(data_mat) ;
new_data = {5} ;
data = [data;new_data]
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!