merge two cells to one in loop
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello all,
I've got two cells A and B. Cell A and B are the exact same size, however within A and B the vector length of the arrays differ. Cell A and B are produced by a loop which extracts data from 10 datasets using data.values, which I then edit and put into cells. I now want to add both of these cells together to get a third cell (C) which is the same size of A and B (so every value in A gets summed with the overlaping value of B). What is the most novice way of doing this?Thanks in advance
for i=1:10
Adata{i}=data.values(:,192);
Araw = cellfun(@abs,Araw,'UniformOutput',false);
Bdata{i}=data.values(:,193);
Araw = cellfun(@abs,Braw,'UniformOutput',false);
A = cellfun(@(x) x*1250/100,Araw,'UniformOutput',false);
B = cellfun(@(x) x*1250/100,Araw,'UniformOutput',false);
end
0 commentaires
Réponses (1)
Prabhan Purwar
le 20 Jan 2020
Hi,
Following code may help
clc
close all
clear
data.values=ones(20,200);
for i=1:10
A{i}=data.values(:,192);
B{i}=data.values(1:10,193);
a=A{i};
b=B{i};
sx=size(a,1);
sy=size(b,1);
amin=min(sx,sy);
if sx>sy
S{i}=[a(1:amin)+b(1:amin);a(amin+1:end)];
elseif sx<sy
S{i}=[a(1:amin)+b(1:amin);b(amin+1:end)];
else
S{i}=[a(1:amin)+b(1:amin)];
end
end
Here I have used simple addition of cell array elements in a one-to-one manner, although the same could be achieved using cellFun().
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!