フィルターのクリア

combining lots of vectors of unequal length

1 回表示 (過去 30 日間)
Haneya Qureshi
Haneya Qureshi 2018 年 4 月 3 日
コメント済み: Stephen23 2018 年 4 月 3 日
i have: a=[1 2 3 0 0] b=[4 5 6 7 0 0 0] c=[8 9] i want: d= [a b c] with zeros removed d=[1 2 3 4 5 6 7 8 9]
Is there a generic code for this? because i have lots of vectors like a,b and c and their length is very large and unequal

回答 (1 件)

Akira Agata
Akira Agata 2018 年 4 月 3 日
I don't think there is a generic code. How about making a function to do this, like:
function [d1,d2] = yourFunction(a,b,c)
d1 = [a,b,c];
idx = d1 == 0;
d2 = d1(~idx);
end
Here is an example.
>> [d1,d2] = yourFunction([1 2 3 0 0],[4 5 6 7 0 0 0],[8 9])
d1 =
1 2 3 0 0 4 5 6 7 0 0 0 8 9
d2 =
1 2 3 4 5 6 7 8 9

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by