How to subtract coloumn vectors of a cell array

조회 수: 1 (최근 30일)
Levente Gellért
Levente Gellért 2021년 9월 26일
답변: Stephen23 2021년 9월 26일
Dear Community,
I have a cell array, with each cell containing n by m matrix. I would like to use cellfun and minus, and subtract the first coloumn from the second one, and add the value of 1. (like: result=(second coloumn-first coloumn)+1)
Unfortunately I do not exacty understand the nature of cellfun, to solve this.
Please find attached an example cell, and a result.mat showing, what would I like to get, when perform the calculation in the first cell.
Many thanks for you suggestions!
lg

답변 (1개)

Stephen23
Stephen23 2021년 9월 26일
inp = load('mycell.mat').mycell; % input data
fun = @(m) 1+diff(m,1,2); % anonymous function
out = cellfun(fun,inp, 'uni',0) % calculate
out = 12×1 cell array
{100×1 double} {100×1 double} {100×1 double} { 20×1 double} { 20×1 double} { 20×1 double} {124×1 double} {124×1 double} {124×1 double} {101×1 double} {101×1 double} {101×1 double}
out{1} % compare first cell against expected output
ans = 100×1
10 23 34 17 13 3 512 4 10 37
load('result.mat').result
ans = 100×1
10 23 34 17 13 3 512 4 10 37

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by