Info
This question is closed. Reopen it to edit or answer.
Find does not work according to the condition?
2 views (last 30 days)
Show older comments
I have
a=[1 2 3];
b=[4 5 6 7];
c=[7 2]
How do I make them above different size matrix a single array like as follows:
s=[1 2 3 0;
4 5 6 7;
7 2 0 0];
1 Comment
Answers (2)
Jan
on 5 Aug 2018
Edited: Jan
on 5 Aug 2018
a = [1 2 3];
b = [4 5 6 7];
c = [7 2];
Data = {a, b, c}; % Better use a cell array instead of a bunch of variables
Len = cellfun('prodofzize', Data);
M = zeros(numel(Data), max(Len));
for k = 1:numel(Data)
M(k, 1:Len(k)) = Data{k};
end
By the way: You find some matching functions searching in the FileExchange:
0 Comments
Image Analyst
on 5 Aug 2018
This works:
a=[1 2 3];
b=[4 5 6 7];
c=[7 2]
maxLength = max([length(a), length(b), length(c)])
output = zeros(3, maxLength);
output(1, 1:length(a)) = a;
output(2, 1:length(b)) = b;
output(3, 1:length(c)) = c
find() was not needed.
0 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!