WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

gui+plot

 

wuwo
Forum-Anfänger

Forum-Anfänger


Beiträge: 11
Anmeldedatum: 11.11.08
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 11.11.2008, 17:16     Titel: gui+plot
  Antworten mit Zitat      
hallo leute, gleich mit dem ersten beitrag bin ich lästig. Smile

folgendes m-file für ein gui läuft nicht wie ich es möchte.

die fehlermeldung lautet:

??? In an assignment A(I) = B, the number of elements in B and
I must be the same.

Error in ==> string1>refresh_Callback at 434
x(2) = va*dt + x(1);



Code:
function varargout = string1(varargin)
% STRING1 M-file for string1.fig
%      STRING1, by itself, creates a new STRING1 or raises the existing
%      singleton*.
%
%      H = STRING1 returns the handle to a new STRING1 or the handle to
%      the existing singleton*.
%
%      STRING1('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in STRING1.M with the given input arguments.
%
%      STRING1('Property','Value',...) creates a new STRING1 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before string1_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to string1_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 string1

% Last Modified by GUIDE v2.5 08-Nov-2008 20:08:00

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @string1_OpeningFcn, ...
                   'gui_OutputFcn',  @string1_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 string1 is made visible.
function string1_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 string1 (see VARARGIN)

% Choose default command line output for string1
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes string1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = string1_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;

%-------------------------------------------------------------------------

% handles.hintergrund = imread('X:\file_store\FH!!!!!!!\AINF_mset1\Bergpower 2.0e\4.jpg')
% axes(handles.axes1);
% image(handles.hintergrund);
% axis off;
handles.hintergrund = imread('X:\file_store\FH!!!!!!!\AINF_mset1\Bergpower 2.0e\Bergpower 2.0\unten1.jpg')
axes(handles.axes2);
image(handles.hintergrund);
axis off;
handles.hintergrund = imread('X:\file_store\FH!!!!!!!\AINF_mset1\Bergpower 2.0e\Bergpower 2.0\teifl1.jpg')
axes(handles.axes4);
image(handles.hintergrund);
axis off;
%-------------------------------------------------------------------------
% --- Executes on button press in but_zoom.
function but_zoom_Callback(hObject, eventdata, handles)
% hObject    handle to but_zoom (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

zoom on;
%-------------------------------------------------------------------------
% --- Executes on button press in pushbutton4.
function but_overview_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

zoom out;
%-------------------------------------------------------------------------
% --- Executes on button press in but_pan.
function but_pan_Callback(hObject, eventdata, handles)
% hObject    handle to but_pan (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

pan xon;
%-------------------------------------------------------------------------


%set(handles.popupmenu1,'Visible','on'); %Pop up Menu 1 einblenden
% set(handles.popupmenu2,'Visible','on'); %Pop up Menu 2 einblenden


% popup_sel_index1 = get(handles.popupmenu1, 'Value'); %Auswahlen - Settings Pup up Menü1
% switch popup_sel_index1
%     case 1
%         t=x_p;
%         P=y4;
%     case 2
%         x1=x_p;
%         Y=y5;
%     case 3
%         x1=x_s;
%         Y=y1;
%     case 4
%         x1=x_s;
%         Y=y2;
%     case 5    
       
% end

% popup_sel_index2 = get(handles.popupmenu2, 'Value');   %%Auswahlen - Settings Pup up Menü2
% switch popup_sel_index2
%     case 1
%         plot(t,x);
%     case 2
%         plot(t1,vf1);
%  end


%---------------------------------------------------------------Cursor
% --- Executes on button press in cursor_on.
function cursor_on_Callback(hObject, eventdata, handles)
% hObject    handle to cursor_on (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

dualcursor on


dualcursor([0 10], [-.13 .3;-.13 .4])

%---------------------------------------------------button zum schließen
function close_Callback(hObject, eventdata, handles)
% hObject    handle to close (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

selection = questdlg(['Close string instability?'],...
                     ['Close ' ],...
                     'Yes','No','Yes');
if strcmp(selection,'No')
    return;
end

delete(handles.figure1)

%-------------------------------------------------------------------------

% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'string1') returns popupmenu2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu2


% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


set(hObject, 'String', {'diagram options', 's-t (velocity)', 'v-t (acceleration)'})

%-------------------------------------------------------------------------

% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'string1') returns popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1


% --- Executes during object creation, after setting all properties.
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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


set(hObject, 'String', {'1', '5', '10', '20', '50'})

%-------------------------------------------------------------------------


function v0_Callback(hObject, eventdata, handles)
% hObject    handle to v0 (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,'string1') returns contents of v0 as text
%        str2double(get(hObject,'string1')) returns contents of v0 as a double
%global v0;

v0 = str2num(get(hObject,'String'));
 
%checks to see if input is empty. if so, default input1_editText to zero
if (isempty(v0))
     set(hObject,'String','0')
end
guidata(hObject, handles);

% v0 = str2double(get(hObject, 'String'));
% if isnan(v0)
%     set(hObject, 'String', 0);
%     errordlg('Input must be a number','Error');
% end
%
% % speichern des neuen eintrages:
%
% handles.metricdata.v0 = v0;
% guidata(hObject,handles);

% --- Executes during object creation, after setting all properties.
function v0_CreateFcn(hObject, eventdata, handles)
% hObject    handle to v0 (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 v2_Callback(hObject, eventdata, handles)
% hObject    handle to v2 (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,'string1') returns contents of v2 as text
%        str2double(get(hObject,'string1')) returns contents of v2 as a double

v2 = str2num(get(hObject,'String'));
 
%checks to see if input is empty. if so, default input1_editText to zero
if (isempty(v2))
     set(hObject,'String','0')
end
guidata(hObject, handles);

% global v2;
%
% v2 = str2double(get(hObject, 'String'));
% if isnan(v2)
%     set(hObject, 'String', 0);
%     errordlg('Input must be a number','Error');
% end
%
% % speichern des neuen eintrages:
%
% handles.metricdata.v2 = v2;
% guidata(hObject,handles)

% --- Executes during object creation, after setting all properties.
function v2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to v2 (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 radius_Callback(hObject, eventdata, handles)
% hObject    handle to radius (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,'string1') returns contents of radius as text
%        str2double(get(hObject,'string1')) returns contents of radius as a double

radius = str2num(get(hObject,'String'));
 
%checks to see if input is empty. if so, default input1_editText to zero
if (isempty(radius))
     set(hObject,'String','0')
end
guidata(hObject, handles);

% global radius;
%
% radius = str2double(get(hObject, 'String'));
% if isnan(radius)
%     set(hObject, 'String', 0);
%     errordlg('Input must be a number','Error');
% end

% speichern des neuen eintrages:

% handles.metricdata.radius = radius;
% guidata(hObject,handles)

% --- Executes during object creation, after setting all properties.
function radius_CreateFcn(hObject, eventdata, handles)
% hObject    handle to radius (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 winkel_Callback(hObject, eventdata, handles)
% hObject    handle to winkel (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,'string1') returns contents of winkel as text
%        str2double(get(hObject,'string1')) returns contents of winkel as a double

winkel = str2num(get(hObject,'String'));
 
%checks to see if input is empty. if so, default input1_editText to zero
if (isempty(winkel))
     set(hObject,'String','0')
end
guidata(hObject, handles);

% global winkel;
%
% winkel = str2double(get(hObject, 'String'));
% if isnan(winkel)
%     set(hObject, 'String', 0);
%     errordlg('Input must be a number','Error');
% end

% speichern des neuen eintrages:

% handles.metricdata.winkel = winkel;
% guidata(hObject,handles)

% --- Executes during object creation, after setting all properties.
function winkel_CreateFcn(hObject, eventdata, handles)
% hObject    handle to winkel (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 button press in refresh.
function refresh_Callback(hObject, eventdata, handles)
% hObject    handle to refresh (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

v0 = get(handles.v0,'string');
v2 = get(handles.v2,'string');
radius = get(handles.radius,'string');
winkel = get(handles.winkel,'string');


 r=str2num(radius)
 phi=str2num(winkel)
 

rb=0.7;      %Reibkoeffizient mü
g=9.81;      %Erdbeschl.
abr = 3;     %bremsverzögerung vor der Kurve-3m/s
abs = 2;     %beschleunigung nach der Kurve 2m/s
dt=0.01;

 %v0 = v0/3.6    %in m/s
 %v2 = v2/3.6
 va = get(handles.v0,'string')/3.6;    %in m/s
 vb = get(handles.v2,'string')/3.6;
 

%syms x;
x(1) = 0;
x(2) = va*dt + x(1);

vf1 = v0;
vf2 = vf1 - abr*dt;

vk=sqrt(r*g*rb);              %Kurvengeschwindigkeit
kl=(r*pi*phi)/(180)       %Kurvenlänge

n = 1;

%Fahrer 1
while vf1(n) > vk
    n = n+1;
    x(n+1) = 2*x(n) - x(n-1) - abr*dt^2
   
%    v(n+1) = (x(n+1) - x(n)) / dt;
    vf1(n) = (x(n+1)-x(n)) / dt;   %Geschw. Fahrer 1
end

i=1

bw = x(n);   %bw.....Bremsweg


while x(n) < bw+kl %kl.....kurvenlänge
    x(n+1) = x(n) + vk*dt;
    vf1(n) = (x(n+1)-x(n)) / dt;
   
    n = n+1;
end

while vf1(n-1) < v2
    x(n+1) = 2*x(n) - x(n-1) + abs*dt^2;
    vf1(n) = (x(n+1)-x(n)) / dt;
   
    n = n+1;
end

t = 0:dt:(n-1)*dt;
t1 = dt:dt:(n-1)*dt;   %Intervall der Geschw. um eins kürzer da durch die Ableitung ein Wert wegfällt
vf1 = vf1*3.6;      %umrechung von m/s auf km/h


guidata(hObject, handles);
axes(handles.axes1);
plot(t,x,t1,vf1,'c+:');  
grid on;
ylabel('yachse');
xlabel('xachse');
hold


Unbenannt-1 Kopie (Small).jpg
 Beschreibung:

Download
 Dateiname:  Unbenannt-1 Kopie (Small).jpg
 Dateigröße:  30.69 KB
 Heruntergeladen:  692 mal
Private Nachricht senden Benutzer-Profile anzeigen


dib0r
Forum-Guru

Forum-Guru


Beiträge: 413
Anmeldedatum: 09.05.08
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 11.11.2008, 19:10     Titel:
  Antworten mit Zitat      
Hallo,

Code:
va = get(handles.v0,'string')/3.6;    %in m/s
Du musst den String erst wieder in eine Zahl umwandeln (z.B. mit "str2double"), ansonsten nimmt er glaub ich die ASCII-Werte eines jeden einzelnen Zeichens her (so ergibt '34'/1 -> 51 52). Den Rest habe ich mir noch nicht angesehen, aber die Fehlermeldung kommt daher, dass dir deine Gleichung "x(2) = ...." nicht ein Skalar, sondern ein Array zurückliefert - und du versuchst dies in ein Skalar zu schreiben - was natürlich nicht geht.

Achja, versuch bitte beim nächsten Mal nicht den ganzen Source-Code, sondern nur den relevanten Teil (Minimalbeispiel) zu posten.

MfG
Private Nachricht senden Benutzer-Profile anzeigen
 
Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.
Du kannst Dateien in diesem Forum posten
Du kannst Dateien in diesem Forum herunterladen
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2024 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.