How can I write three different size vectors in a matrix ?

5 次查看(过去 30 天)
I have two different variables and a counter (i) .One of them is a counter result(k). Second one is a function result of the counter(f(k)). All of them a vector but different sizes. The k vector has 9 variables, so function result has 9 component. I want to write them together in a matrix. I show a example below.
i = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
k = 3 5 9 10 11 12 13 15 18
f(k) = 0.1 0.2 0.5 0.7 0.75 0.8 0.82 0.90 0.90
result = [ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ;
0 0 3 0 5 0 0 0 9 10 11 12 13 0 15 0 0 18 0 0 ;
0 0 0.1 0 0.2 0 0 0 0.5 0.7 0.75 0.8 0.82 0 0.90 0 0 0.90 0 0 ]
Please help me.

采纳的回答

DGM
DGM 2021-4-25
This probably isn't the most robust way, but here's my try.
i = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20];
k = [3 5 9 10 11 12 13 15 18];
f = [0.1 0.2 0.5 0.7 0.75 0.8 0.82 0.90 0.90];
mk = ismember(i,k);
A = zeros(3,numel(i));
A(1,:) = i;
A(2,mk) = k;
A(3,mk) = f;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by