Adding 2 different length array
Mostra commenti meno recenti
I have problem in adding 2 different length array e.g x=[1 2 3 4 5 6 ]', Y =[ 3 5 7 8 ]' Ans= 4 7 10 13 6 but I do not know how to get this answer ? in my code I have tried
dir_list=dir('v1_ch.txt');
vec1=[];
for j=1:12
data=dlmread(dir_list((j-1)*13+k).name,';',3 );
latitude=data(:,1);
longitude=data(:,2);
ch4=data(:,3);
vec1=vec1+ch4; % here I tried to add array together
end
but it does not work ?
1 Commento
Jan
il 23 Ott 2011
Please edit your question and use the standard code formatting as explained in the "Markup help" link.
Risposta accettata
Più risposte (1)
Azmat Ameen
il 17 Dic 2020
Modificato: Azmat Ameen
il 17 Dic 2020
function[t,x]=padding(t1,t2,x1,x2)
t=min(min(t1),min(t2)):max(max(t1),max(t2));
y1=zeros(1,length(t));
y2=y1;
y1((t>=min(t1))&(t<=max(t1)))=x1;
y2((t>=min(t2))&(t<=max(t2)))=x2;
x=(y1+y2)
stem(t,x)
end
Use this function to pad zeros and you will get the addition of two different array with different length.
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!