Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Find does not work according to the condition?

1 visualizzazione (ultimi 30 giorni)
VIJAY
VIJAY il 5 Ago 2018
Chiuso: MATLAB Answer Bot il 20 Ago 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];

Risposte (2)

Jan
Jan il 5 Ago 2018
Modificato: Jan il 5 Ago 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 il 5 Ago 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.

Questa domanda è chiusa.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by