Effacer les filtres
Effacer les filtres

Hello, i keep getting error of: "Brace indexing is not supported for variables of this type." thanks for the help

3 vues (au cours des 30 derniers jours)
function varargout = smooth(varargin)
% SMOOTH MATLAB code for smooth.fig
% SMOOTH, by itself, creates a new SMOOTH or raises the existing
% singleton*.
%
% H = SMOOTH returns the handle to a new SMOOTH or the handle to
% the existing singleton*.
%
% SMOOTH('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SMOOTH.M with the given input arguments.
%
% SMOOTH('Property','Value',...) creates a new SMOOTH or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before smooth_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to smooth_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 smooth
% Last Modified by GUIDE v2.5 21-Apr-2020 09:53:57
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @smooth_OpeningFcn, ...
'gui_OutputFcn', @smooth_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 smooth is made visible.
function smooth_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 smooth (see VARARGIN)
% Choose default command line output for smooth
handles.output = hObject;
% add our own data fields
handles.minFreq = 1;
handles.maxFreq = 10;
handles.amp = 8;
handles.freq = 2.5;
handles.t = 0:0.001:1;
handles.x = handles.amp * sin(2*pi*handles.freq*handles.t);
handles.noise = randn(1,length(handles.t));
handles.radiobutton3 = sin(2*pi*60*handles.t);
handles.window = NaN;
handles.windowIndex = 6;
handles.addRandom = true;
handles.addInterference = false;
handles.plotOriginal = false;
handles.plotNoisy = true;
handles.plotSmoothed = true;
set(handles.amplEdit,'String',num2str(handles.amp));
fs = (handles.freq - handles.minFreq) / (handles.maxFreq - handles.minFreq);
set(handles.freqSlider,'Value',fs);
set(handles.originalBox,'value',handles.plotOriginal);
set(handles.noisyBox,'value',handles.plotNoisy);
set(handles.smoothedBox,'value',handles.plotSmoothed);
set(handles.windowMenu,'Value',handles.windowIndex);
str = get(handles.windowMenu, 'String');
handles.window = str2double(str{handles.windowIndex});
set(handles.radiobutton2,'Value',1);
plotit(handles);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes smooth wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = smooth_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;
% --- Executes on slider movement.
function freqSlider_Callback(hObject, eventdata, handles)
% hObject handle to freqSlider (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
fs = get(handles.freqSlider,'Value');
handles.freq = handles.minFreq + fs * (handles.maxFreq - handles.minFreq);
handles.x = handles.amp * sin(2*pi*handles.freq*handles.t);
plot(handles.axes,handles.t,handles.x);
set(handles.axes,'XMinorTick','on');
grid on
% Update handles structure
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function freqSlider_CreateFcn(hObject, eventdata, handles)
% hObject handle to freqSlider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
function amplEdit_Callback(hObject, eventdata, handles)
% hObject handle to amplEdit (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 amplEdit as text
% str2double(get(hObject,'String')) returns contents of amplEdit as a double
amp = str2double(get(hObject,'String'));
if isnan(amp) || ~isreal(amp)
% isdouble returns NaN for non-numbers and f1 cannot be complex
% Disable the Plot button and change its string to say why
set(hObject,'String',num2str(handles.amp));
else
if abs(amp) > 100
amp = 100;
set(hObject,'String',num2str(amp));
end
handles.amp = amp;
handles.x = handles.amp * sin(2*pi*handles.freq*handles.t);
plot(handles.axes,handles.t,handles.x);
set(handles.axes,'XMinorTick','on');
grid on
guidata(hObject, handles);
end
% --- Executes during object creation, after setting all properties.
function amplEdit_CreateFcn(hObject, eventdata, handles)
% hObject handle to amplEdit (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 windowMenu.
function windowMenu_Callback(hObject, eventdata, handles)
% hObject handle to windowMenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns windowMenu contents as cell array
% contents{get(hObject,'Value')} returns selected item from windowMenu
% Menu
sel = get(hObject,'String');
handles.window = str2double(sel{get(hObject,'Value')});
plotit(handles);
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function windowMenu_CreateFcn(hObject, eventdata, handles)
% hObject handle to windowMenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox 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 signalControl_SelectionChangeFcn(hObject,eventdata,handles)
switch get(eventdata.NewValue,'Tag')
% Get Tag of selected object.
case 'radiobutton1'
handles.addRandom = false;
handles.addInterference = false;
case 'radiobutton2'
handles.addRandom = true;
handles.addInterference = false;
case 'radiobutton3'
handles.addRandom = false;
handles.addInterference = true;
case 'radiobutton4'
handles.addRandom = true;
handles.addInterference = true;
end
plotit(handles);
guidata(hObject, handles);
% --- Executes on button press in originalBox.
function originalBox_Callback(hObject, eventdata, handles)
% hObject handle to originalBox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of originalBox
handles.plotOriginal = get(hObject,'value');
plotit(handles);
guidata(hObject, handles);
% --- Executes on button press in noisyBox.
function noisyBox_Callback(hObject, eventdata, handles)
% hObject handle to noisyBox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of noisyBox
handles.plotOriginal = get(hObject,'value');
plotit(handles);
guidata(hObject, handles);
% --- Executes on button press in smoothedBox.
function smoothedBox_Callback(hObject, eventdata, handles)
% hObject handle to smoothedBox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of smoothedBox
handles.plotOriginal = get(hObject,'value');
plotit(handles);
guidata(hObject, handles);
  6 commentaires
Image Analyst
Image Analyst le 21 Avr 2020
Remove the semicolon and add whos to your oepning function:
str = handles.windowMenu.String
whos str
Set a breakpoint right after that whos and tell me what you see in the command window. Also, what values did you load into the windowMenu control's string property in GUIDE?
arthur doroshev
arthur doroshev le 21 Avr 2020
str =
'1'
Name Size Bytes Class Attributes
str 1x1 2 char

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 21 Avr 2020
So there is only one string in there and hence it's not a cell array but a simple character array. You'll need to put str into a cell first
str = {handles.windowMenu.String};
and then you'll need to make sure that handles.windowIndex is not more than 1 or the current length of str
if handles.windowIndex > length(str)
warningMessage = sprintf('Error: you are trying to access string #%d in str, but str has only %s strings in it!',...
handles.windowIndex, length(str));
uiwait(errordlg(warningMessage));
handles.window = str{1};
handles.windowIndex = length(str); % Optional - if you want to fix the value or not.
else
handles.window = str2double(str{handles.windowIndex});
end

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by