How can I write three different size vectors in a matrix ?
1 view (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
DGM
on 25 Apr 2021
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;
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!