How to get an array of external bits in matlab gui?
Info
This question is closed. Reopen it to edit or answer.
Show older comments
How to get an array of external bits in matlab gui?
I tried with bitdouble variable and str2double but it was not successful.
function varargout = denemeproje(varargin)
% DENEMEPROJE MATLAB code for denemeproje.fig
% DENEMEPROJE, by itself, creates a new DENEMEPROJE or raises the existing
% singleton*.
%
% H = DENEMEPROJE returns the handle to a new DENEMEPROJE or the handle to
% the existing singleton*.
%
% DENEMEPROJE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in DENEMEPROJE.M with the given input arguments.
%
% DENEMEPROJE('Property','Value',...) creates a new DENEMEPROJE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before denemeproje_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to denemeproje_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help denemeproje
% Last Modified by GUIDE v2.5 28-Apr-2019 18:41:52
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @denemeproje_OpeningFcn, ...
'gui_OutputFcn', @denemeproje_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before denemeproje is made visible.
function denemeproje_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to denemeproje (see VARARGIN)
% Choose default command line output for denemeproje
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes denemeproje wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = denemeproje_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function pushbutton1_Callback(hObject, eventdata, handles)
function popupmenu1_Callback(hObject, eventdata, handles)
state=get(handles.popupmenu1,'value');
global bitdouble
switch state
case 1
h=[bitdouble];
n=1;
h=~h;
l=length(h);
h(l+1)=1;
while n<=length(h)-1;
t=n-1:0.001:n;
if h(n) == 0
if h(n+1)==0
y=-(t<n)+2*(t<n-0.5)+1*(t==n);
else
y=-(t<n)+2*(t<n-0.5)-1*(t==n);
end
d=plot(t,y);grid on;
title('Line code MANCHESTER');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -20 20]);
else
if h(n+1)==0
y=(t<n)-2*(t<n-0.5)+1*(t==n);
else
y=(t<n)-2*(t<n-0.5)-1*(t==n);
end
d=plot(t,y);grid on;
title('Line code MANCHESTER');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -20 20]);
end
n=n+1;
end
case 2
h=[bitdouble];
est_initial=-1;
con=est_initial;
long=length(h);
n=1;
ac=[];
bits=[];
h(long+1)=0;
while n<=long
if h(n)==1
bit=[ones(1,100)];
s=[con*ones(1,50) -con*ones(1,50)];
con=con*-1;
else
bit=[zeros(1,100)];
s=[con*ones(1,100)];
if h(n+1)==0
con=con*-1;
end
end
ac=[ac s];
bits=[bits bit];
n=n+1;
s=[];
end
axes(handles.axes1);
a = plot(ac,'LineWidth',2.5)
title('MILLER CODE')
set(a,'LineWidth',2.5)
axis([0 (length(h)-1) -20 20])
grid on
case 3
bit_array=(bitdouble);
rb=20000;bit_period=1/rb;
data_duration=bit_period*length(bit_array);
cmi_signal=[];V_High=5;V_Low=-5;
bit_duration_sample=500;
if(bit_array(1)==1)
cmi_signal=[cmi_signal V_High*ones(1,500)];
isaret=5;
else
cmi_signal=[cmi_signal V_Low*ones(1,250) V_High*ones(1,250)];
end
for i=2:length(bit_array)
if(bit_array(i)==1)
isaret=(-1)*isaret;
cmi_signal=[cmi_signal isaret*ones(1,500)];
else
cmi_signal=[cmi_signal V_Low*ones(1,250) V_High*ones(1,250)];
end
end
t=linspace(0,data_duration,length(cmi_signal));
plot(t,cmi_signal,'k-','LineWidth',2.5);
axis([0 data_duration -20 20]);grid;
case 4
h=[bitdouble];
n=1;
l=length(h);
h(l+1)=1;
while n<=length(h)-1;
t=n-1:0.001:n;
if h(n) == 0
if h(n+1)==0
y=(t>n);
else
y=(t==n);
end
d=plot(t,y);grid on;
title('Line code UNIPOLAR NRZ');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -20 20]);
else
if h(n+1)==0
y=(t<n)-0*(t==n);
else
y=(t<n)+1*(t==n);
end
d=plot(t,y);grid on;
title('Line code UNIPOLAR NRZ');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -20 20]);
end
n=n+1;
end
case 5
h=[bitdouble];
n=1;
l=length(h);
h(l+1)=1;
while n<=length(h)-1;
t=n-1:0.001:n;
if h(n) == 0
if h(n+1)==0
y=(t>n);
else
y=(t==n);
end
d=plot(t,y);grid on
title('Line code UNIPOLAR RZ');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -20 20]);
else
if h(n+1)==0
y=(t<n-0.5);
else
y=(t<n-0.5)+1*(t==n);
end
d=plot(t,y);grid on;
title('Line code UNIPOLAR RZ');
set(d,'LineWidth',2.5);
hold on;
axis([0 length(h)-1 -20 20]);
end
n=n+1;
end
end
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
global bitdouble
bitdouble=str2double(get(hObject,'String'));
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (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
% --- Executes on selection change in popupmenu1.

Answers (1)
Guillaume
on 28 Apr 2019
0 votes
I have no idea what an array of external bits is.
Furthermore, you've posted a wall of code with not a single comment explaining what it does and many variables with no meaningful names. I doubt many people will spend the time trying to understand it.
You really need to explain a lot more clearly what you're trying to do and what the problem is.
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!