load matlab file to current workspace

Hi,
I use this code to load .m file
[filename, pathname] = uigetfile( ...
{'*.m', 'All matlab-Files (*.m)'; ...
'*.*','All Files (*.*)'}, ...
'Select Matlab File');
save(fullfile(pwd, filename));
but! .. when i open it after loading, its content was changed to undefined character like this:
ه3"av خًOتJM.aà„ت?A?GB‰?JKـ2sR‎?sS‹!b?HْYذô3Bظ0s? ü¬ؤ”ش ¨™??ô³ èga?ِwٍ?és  ڈ?ح^?ك%5/?³83/]/?,?
how i can save it with orginal content (matlab code)?

댓글 수: 4

Honglei Chen
Honglei Chen 2011년 12월 15일
Could you clarify exactly what you want to do? save command saves the workspace variables, not the file. Besides, you already have the file and what's the point to save it again? Do you mean you want to run the script and save the result?
Amani
Amani 2011년 12월 16일
hmm .. I have list box contain items their type is file.m ,
and i put "add new file" button , to add this new file to my list box (and add it to current dirctory too).
How i can save this new file and load it ? so, i can use it as .m code.
I hope you understand what i want,,
and thanx for your response .
Fangjun Jiang
Fangjun Jiang 2011년 12월 16일
To "add it to current directory too", use copyfile()
Amani
Amani 2011년 12월 19일
Thaaanx alot ^_^

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

 채택된 답변

Naz
Naz 2011년 12월 16일

1 개 추천

uigetfile gets the path, not the data. Before saving you need to load your file. Thus, use function load and give it the path obtained from uigetfile. After you load the data into the variable, you can save it using save function. Also, since you have the filename and the pathname, you dont need to use fullfile. The full path can be provided as follows:[ pathname filename ] As far as I understand you are trying to create a bank of addresses and display them in the listbox, as well as save the data to file. For updating your listbox use the fillowing idea:
your code here
....
currentDATA=get(listbox.handles,string);
updatedDATA={currentDATA; pathfile filename};
set(handles.listbox,string,num2str(updatedDATA)); %updates the listbox
save([pathname filename],'updatedDATA'); saves the data to file

댓글 수: 4

Fangjun Jiang
Fangjun Jiang 2011년 12월 16일
correction: most likely, it is handles.listbox
need to use fullfile(pathname,filename)
Naz
Naz 2011년 12월 19일
@ Fangjin. Fixed it
Amani
Amani 2011년 12월 19일
Thaanx for you ^_^
please i have one problem :\
I want to cut the last two characters from such string which i got it from a variable .. like "filename" in the above code .. how ?
I mean that i want to cut the .m when i get the file name
form "filename" variable to show it in the list box without .m
Walter Roberson
Walter Roberson 2011년 12월 20일
filename(1:end-2)

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

추가 답변 (0개)

카테고리

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

질문:

2011년 12월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by