Problema unión dos direcciones
Publicado por Vicente (4 intervenciones) el 20/03/2012 19:20:10
Hola, estoy haciendo una GUI y me he encontrado con el siguiente problema. Tengo una carpeta que tiene dos archivos con datos (Datos1 y Datos2). En lugar de poner directamente la dirección de esos archivos lo que hago es primero preguntar en dónde se encuentra esa carpeta y guardar esa dirección.
Por ejemplo: pathanme=uigetdir;
pathname='C:Users\Desktop\Datos\';
Después, según quieras ver un archivo u otro, se te asigna la dirección de ese archivo dentro de esa carpeta, por ejemplo, si escojo:
Datos1----> situacion='Datos1.txt';
Al pulsar el botón dibujar, quiero que se importe ese archivo, pero siempre me sale que no lo puede hacer porque la dirección que le mando es incorrecta. Lo que escribo es:
Direccion_completa=strcat(pathname,situacion);
datos=importdata(Direccion_completa)<----------ESTE ES EL ERROR
¿Alguien me puede echar una mano? Os dejo el código entero por si no me he explicado correctamente.
Por ejemplo: pathanme=uigetdir;
pathname='C:Users\Desktop\Datos\';
Después, según quieras ver un archivo u otro, se te asigna la dirección de ese archivo dentro de esa carpeta, por ejemplo, si escojo:
Datos1----> situacion='Datos1.txt';
Al pulsar el botón dibujar, quiero que se importe ese archivo, pero siempre me sale que no lo puede hacer porque la dirección que le mando es incorrecta. Lo que escribo es:
Direccion_completa=strcat(pathname,situacion);
datos=importdata(Direccion_completa)<----------ESTE ES EL ERROR
¿Alguien me puede echar una mano? Os dejo el código entero por si no me he explicado correctamente.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
function varargout = Libreria(varargin)
clc
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Libreria_OpeningFcn, ...
'gui_OutputFcn', @Libreria_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 Libreria is made visible.
function Libreria_OpeningFcn(hObject, ~, handles, varargin)
set(handles.axes1,'Visible','off');
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = Libreria_OutputFcn(~, ~, handles)
varargout{1} = handles.output;
% --- Executes on button press in Boton_buscar_libreria.
function Boton_buscar_libreria_Callback(hObject, ~, handles)
[pathname]=uigetdir;
set(handles.edit1,'String',pathname);
handles.Direccion=pathname;
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes when selected object is changed in uipanel1.
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
if hObject==handles.uno
situacion='Datos1.txt';
elseif hObject==handles.dos
situacion='Datos2.txt';
end
handles.situacion=situacion;
guidata(hObject, handles);
% --- Executes on button press in Boton_dibujar.
function Boton_dibujar_Callback(hObject, eventdata, handles)
LIBRERIA=handles.Direccion;
SITUACION=handles.situacion;
Direccion_completa=strcat(LIBRERIA,SITUACION);
set(handles.edit2,'String',Direccion_completa);
datos=importdata(Direccion_completa);
matriz=datos.data;
axes(handles.axes1);
plot(matriz(:,1),matriz(:,2),'bo-')
set(handles.axes1,'Visible','on');
guidata(hObject, handles);
Valora esta pregunta


0