MATLAB Answers

manually label data from a variable while looping through and save the labelled data in a new variable

1 ビュー (過去 30 日間)
HT
HT 2020 年 8 月 12 日
コメント済み: HT 2020 年 9 月 11 日
I have some data stored in each row of a variable (example: 190x1800 i.e. 190 samples, each row is a sample). I am stepping through and plotting each sample with code below. I need to save some selected samples and the row no. into two different variables (rw_number & good_samples) upon reviewing the plot (i.e store only good data). How can i do this?
figure
for i=1:8:numSamples
for j=0:1:7
plot(time_scale, Ldata(i+j,:)
axis([0 60 -1 1])
disp(i+j)
pause
%hold on
end
end

  0 件のコメント

サインインしてコメントする。

採用された回答

Mohith Kulkarni
Mohith Kulkarni 2020 年 8 月 27 日
Hi, you would like to review each plot in the loop and store the good samples. To do this, you can use "pushbutton" style property of "uicontrol" function to store the row number in the figure data. Click on the "store" button in the figure to store the row number. Refer to the code below:
f = figure;
data.A = [];
guidata(f,data);
pb = uicontrol('Style','pushbutton','String','store'); %pushbutton
for i=1:8:numSamples
for j=0:1:7
plot(time_scale, Ldata(i+j,:));
axis([0 60 -1 1])
row = i+j;
pb.Callback = {@store,row}; %callback for pushbutton
pause
end
end
rw_number = guidata(f).A; %retrieving data into a variable
good_samples = Ldata(rw_number,:); %accessing the samples
close(gcf); %close the current figure
function store(hObject,eventData,row)
data = guidata(hObject); %retrieving the data struct from figure
data.A= [data.A,row]; %updating row number
guidata(hObject,data); %updating the figure.
end

  3 件のコメント

HT
HT 2020 年 9 月 10 日
Thanks @Mohit or your answer. I tried it but getting erros and no data is being saved in data.A or good_samples. Following is the error:
Error: Functions cannot be indexed using {} or . indexing.
Error in Overlay_Traces (line 62)
rw_number = guidata(f).A; %retrieving data into a variable
Mohith Kulkarni
Mohith Kulkarni 2020 年 9 月 11 日
The direct indexing is possible in later releases. Try the following instead:
rw_number = guidata(f); %first retrieve the struct
rw_number = rw_number.A; %then index into the field

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by