How to calculate the delta

7 次查看(过去 30 天)
Hi,
I have below matrix:
1 3 Signal 6 1 Offset 3
3 5 Deffect 4 0 Offset 6
1 3 Signal 6 1 Offset 3
3 5 Signal 4 0 Offset 6
I want to calculate the delta of the rows ( I struck how to avoid if it is not a double value): My desired output as below:
2 2 Deffect -2 -1 Offset 3
-2 -2 Signal 2 1 Offset -3
2 2 Signal -2 -1 Offset 3
But the text column index may vary in my future input(may not be in column 3 & 6, and the text may appear in many columns)
Many thanks in advance

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2016-8-13
M={1 3 'Signal' 6 1 'Offset' 3
3 5 'Deffect' 4 0 'Offset' 6
1 3 'Signal' 6 1 'Offset' 3
3 5 'Signal' 4 0 'Offset' 6}
idx=all(cellfun(@isnumeric,M))
A=M(2:end,:);
A(:,idx)=num2cell(diff(cell2mat(M(:,idx))))

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Database Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by