Isolate Elements in a Vector

Suppose I have two sets of data:
ab =
0.3570
0.3560
0.3750
0.5150
0.3570
0.3560
0.3750
0.5150
and
ab =
0.4100
0.2500
0.3340
0.5500
0.6250
0.7760
0.3330
0.4100
0.2500
0.3340
0.5500
0.6250
0.7760
0.3330
0.4100
0.2500
0.3340
0.5500
0.6250
0.7760
0.3330
0.4100
0.2500
0.3340
0.5500
0.6250
0.7760
0.3330
0
As you see with the set ab, the numbers repeat itself:
0.3570
0.3560
0.3750
0.5150
and with second set ab:
0.4100
0.2500
0.3340
0.5500
0.6250
0.7760
0.3330
But also note that there is a zero at the end of the second set.
Now if I wanted to construct a vector using one set of data, I would use the following command for the second set to remove that zero
reshape(ab(1:end-1), [], 4);
This would read the vector from the first element to the last, being 0 and remove it with end-1. This also assumes that there are 4 runs.
Obviously this wouldn't work for the first set.
What would I need to change for this to read both sets and to prompt the user how many runs of data there are?

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 1월 24일
편집: Azzi Abdelmalek 2013년 1월 24일

0 개 추천

If you have just these two cases
if ab(end)==0
ab(end)=[]
end
out=reshape(ab,4,[])

댓글 수: 10

T
T 2013년 1월 24일
편집: T 2013년 1월 24일
And to prompt for user input for a 4 or a 2 in a GUI?
Azzi Abdelmalek
Azzi Abdelmalek 2013년 1월 24일
I did'not understand
T
T 2013년 1월 24일
If I want to create a GUI with the guide feature within MATLAB, how can I construct the GUI to include user input by prompting the user to enter in the value, in this case four, and have that descend?
Assuming of course that I have already uploaded the data in file format.
Azzi Abdelmalek
Azzi Abdelmalek 2013년 1월 24일
편집: Azzi Abdelmalek 2013년 1월 24일
In your gui, you can add an edit box where the user can introduce his value
T
T 2013년 1월 28일
Okay so my edit box code reads as follows:
% --- Executes during object creation, after setting all properties.
function runs_CreateFcn(hObject, eventdata, handles)
% hObject handle to runs (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
am I supposed to create the call back function within property inspector? It will not show up in the .m file.
Azzi Abdelmalek
Azzi Abdelmalek 2013년 1월 28일
편집: Azzi Abdelmalek 2013년 1월 28일
In your guide, right click on your edit box , then click on view callback. after that, a callback function will be created in your m fille
T
T 2013년 1월 28일
편집: T 2013년 1월 30일
Ah. I just forgot to update the handles and recall it later for future use that's all.
T
T 2013년 2월 12일
Hi Azzi,
I strangely got the following error using the same data but saved in another directory:
Attempted to access ab(0); index must be a positive integer or
logical.
Error in test>runs_Callback (line 369)
if ab(end)==0 %checks to see if the .mdb file contains a zero at
the end,
Do you know how I can resolve this?
I guess because your ab becomes empty, to understand check this:
a=[];
if a(end)==0;
a(end)=[],
end
T
T 2013년 2월 13일
Actually it would appear that the file in another directory didn't have any data at all!
How could I prompt the user to notify of such an occurence?

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

T
T
2013년 1월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by