merge two cells to one in loop

2 views (last 30 days)
Joost de Witte
Joost de Witte on 15 Jan 2020
Answered: Prabhan Purwar on 20 Jan 2020
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

Answers (1)

Prabhan Purwar
Prabhan Purwar on 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().

Categories

Find more on Data Type Identification in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!