Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Find does not work according to the condition?

1 vue (au cours des 30 derniers jours)
VIJAY
VIJAY le 5 Août 2018
Clôturé : MATLAB Answer Bot le 20 Août 2021
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 commentaire
jonas
jonas le 5 Août 2018
what's the problem with find?

Réponses (2)

Jan
Jan le 5 Août 2018
Modifié(e) : Jan le 5 Août 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:

Image Analyst
Image Analyst le 5 Août 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.

Cette question est clôturée.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by