Change value from index number

조회 수: 15 (최근 30일)
Phudit Kanittasut
Phudit Kanittasut 2021년 5월 3일
답변: Nagasai Bharat 2021년 5월 7일
If loclv is equal to index number , how can I keep the value in Data with index from loclv and change in other to 0 (Change only in column 2
clear
Data = readmatrix('Pure Brain Spectra.csv');
rows=length(Data)
cols=width(Data)
%for i = 2:cols
%hold on
Xlocs = Data(:,1);
Ylocs = Data(:,3);
select = [Xlocs Ylocs]
plot(Data(:,1),Data(:,3));
%for j=1:rows
value = findpeaks(Ylocs,Xlocs);
[pks,locsLiv] = findpeaks(Data(:,2));
%end
%hold off
%end
)

답변 (1개)

Nagasai Bharat
Nagasai Bharat 2021년 5월 7일
Hi,
From my understanding you are trying to replace values in second column in Data with "pks" at locsLiv as index and have rest indices to have a zero.
Adding the following lines of code should do the task
Data(:,2) = 0; % After line [pks,locsLiv] = findpeaks(Data(:,2));
Data(locsLiv,2) = pks ;

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by