i have a column array and i want to subtract each row by the first row and save.please help me in doing this
38 views (last 30 days)
Show older comments
i have a column array and i want to subtract each row by the first row and save.please help me in doing this
0 Comments
Accepted Answer
Star Strider
on 7 Dec 2017
Try this:
Array = randi(9, 5, 4); % Create Data
Out = Array - Array(1,:); % Subtract First Row From All Rows
4 Comments
Star Strider
on 9 Dec 2017
This is obviously homework, so I am reluctant to give a complete solution. I will describe the approach instead.
You can find the indices of the rows matching those criteria with:
idx = find(diff([0; a(:,1)])>2);
(note that it is necessary to add a 0 at the beginning of the vector so the indices are correct), then choose all the rows defined by idx ±2 and delete them by setting them equal to the empty array, [].
That worked when I coded it.
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!