필터 지우기
필터 지우기

Subtract two values of an array and multiply them by a constant

조회 수: 1 (최근 30일)
Troth
Troth 2022년 12월 1일
댓글: Troth 2022년 12월 1일
A = B_Oscilloscope; % Data (1007x94 array)
for k = 1:size(A,2)
[pks, locs] = findpeaks(A(:,k));
[~,ix] = sort(pks);
minpk{:,k} = [pks(ix(1:2)) locs(ix(1:2))];
maxpk{:,k} = [pks(ix(end-1:end)) locs(ix(end-1:end))];
end
maxpk{1} % View Result
minpk{1} % View Result
Hi everyone! Here is my current code:
This creates 2 1x94 arrays with my data (Minimums and Maximums), and each cell contains a 2x2 matrix (second peak and its indice, and first peak and indice). I need to go into each of those matrixes in the arrays and subtract the second entry in the first row by the second entry in the second row, and multiply it by a constant. Similary for both of the arrays I need to subtruct the 1st entry in the minmum row from the 1st in the second, the 2nd entry in the minimum row from the 2nd in the maximum row.
I hope that makes sense.
  댓글 수: 2
Fifteen12
Fifteen12 2022년 12월 1일
It might help if you provide an example of what you'd like to do! Is the constant scalar the same for every cell?
Troth
Troth 2022년 12월 1일
Yes, the constant scalar is the same

댓글을 달려면 로그인하십시오.

채택된 답변

Fifteen12
Fifteen12 2022년 12월 1일
편집: Fifteen12 2022년 12월 1일
If you put everything into an array (rather than a cell array) you can do logial indexing:
rng(1);
constant = 2;
minpk = [randi(10, 2), randi(10, 2), randi(10, 2)]
minpk = 2×6
5 1 2 2 4 5 8 4 1 4 6 7
out = constant * (minpk(1, 2:2:length(minpk)) - minpk(2, 2:2:length(minpk)))
out = 1×3
-6 -4 -4
  댓글 수: 1
Troth
Troth 2022년 12월 1일
For some reason turning it into an array never even occured to me and would make it much easier, thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by