MATLAB Answers

merge two cells to one in loop

4 ビュー (過去 30 日間)
Joost de Witte
Joost de Witte 2020 年 1 月 15 日
回答済み: Prabhan Purwar 2020 年 1 月 20 日 14:41
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 件のコメント

サインイン to comment.

回答 (1 件)

Prabhan Purwar
Prabhan Purwar 2020 年 1 月 20 日 14:41
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 件のコメント

サインイン to comment.

サインイン してこの質問に回答します。

製品


Translated by