フィルターのクリア

subtraction on the cells elements

3 ビュー (過去 30 日間)
johnson saldanha
johnson saldanha 2018 年 12 月 11 日
コメント済み: Guillaume 2018 年 12 月 11 日
i have a cell array x of size 12*1
and the cells are column vectors of type double
x{1,1}=[1 2 5 6 7 7 8 ];
x{2,1}=[ 1 2 6 6 7 8 8]
and so on
i want the output y as a cell array with
y{1,1}=[1 1 3 1 1 0 1];
y{2,1}=[1 1 4 0 1 1 0];
the elements of the cell in the output should be the difference i-(i-1). let the first element be as it is it. start with i =2:length x{i,1}
for each each cell the operation shouldbe done and stored in a different cell
  1 件のコメント
johnson saldanha
johnson saldanha 2018 年 12 月 11 日
編集済み: Guillaume 2018 年 12 月 11 日
acc={}
for i=1:size(out,1)
y=out{i,1};
for i=2:length(y)
acc(i)=y(i)-y(i-1);
end
acc{i,1}=num2cell(acc);
end
Conversion to cell from double is not possible.
Error in accelerationrate (line 66)
acc(i)=y(i)-y(i-1);
i tried this and im getting this error.

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2018 年 12 月 11 日
Note that [1 2 5 6 7 7 8 ] in your example is a row vector, not a column vector as you state. If the content of the cells are indeed column vectors then you'll have to change the , into ; where indicated
%demo data
x = num2cell(randi(10, 12, 10), 2)
%processing
y = cellfun(@(vec) [vec(1), diff(vec)], x, 'UniformOutput', false) %replace [vec(1), by [vec(1); if working on column vectors
or if you want to use a loop instead of cellfun:
y = cell(size(x)); %preallocation
for idx = 1:numel(x)
y{idx} = [x{idx}(1), diff(x{dix})]; %replace , by ; for column vectors
end
  2 件のコメント
johnson saldanha
johnson saldanha 2018 年 12 月 11 日
ifi have to make the first row in every cell element as 0 how do i do it
Guillaume
Guillaume 2018 年 12 月 11 日
Replace vec(1) or x{idx}(1) by 0.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by