save ascii from edit uicontrol

2 vues (au cours des 30 derniers jours)
Muhammad Habibie
Muhammad Habibie le 29 Oct 2015
Commenté : Stephen23 le 1 Nov 2015
1). I have m file with 16 edit text using uicontrol like this :
edit16=uicontrol('parent',win1,...
'units','points',...
'position',[320 60 30 15],...
'backgroundcolor',[1 1 1],...
'style','Edit',...
'string','0',...
'fontname','arial',...
'fontsize',10);
Save=uicontrol('parent',win1,...
'units','points',...
'position',[30 20 80 15],...
'style','pushbutton',...
'callback','save',...
'string','Save',...
'fontname','arial',...
'fontsize',10);
and try tosave ascii using this save.m
a=get(edit1,'String');
b=get(edit2,'String');
c=get(edit3,'String');
d=get(edit4,'String');
e=get(edit5,'String');
f=get(edit6,'String');
g=get(edit7,'String');
h=get(edit8,'String');
i=get(edit9,'String');
j=get(edit10,'String');
k=get(edit11,'String');
l=get(edit12,'String');
m=get(edit13,'String');
n=get(edit14,'String');
o=get(edit15,'String');
p=get(edit16,'String');
save red.txt a b c d e f g h i j k l m n o p -ascii
and i cant save it,the error :
Attempt to execute SCRIPT save as a function:
D:\gui\save.m
Error in save (line 37)
save('a', 'b', 'c',
'd','e','f','g','h','i','j','k','l','m','n','o','p', '-ASCII');
Error while evaluating uicontrol Callback
2). And i wonder how to save this ASCII file in any folder,what is the command?

Réponse acceptée

Walter Roberson
Walter Roberson le 29 Oct 2015
You need to name your save.m something else, something that is not the name of any MATLAB routine that is called upon by the code. You know that the "save" command inside your save.m is intended to refer to the built-in save command, but MATLAB says "Oh, you overrode save.m with your own code, okay, guess I need to call that code, even if it is the same file I'm already executing..."
You can specify a different location to save to:
save('C:\Documents and Settings\Thundercats\red.txt', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', '-ascii')
  3 commentaires
Walter Roberson
Walter Roberson le 29 Oct 2015
Quoting the documentation on save -ascii:
Use one of the text formats to save MATLAB numeric values to text files. In this case:
Each variable must be a two-dimensional double array.
The output includes only the real component of complex numbers.
MATLAB writes data from each variable sequentially to the file. If you plan to use the load function to read the file, all variables must have the same number of columns. The load function creates a single variable from the file.
In other words, using -ascii is the wrong thing to use for string variables.
You should fopen() a file, fprintf() the values in the appropriate format, and fclose() the file.
Muhammad Habibie
Muhammad Habibie le 29 Oct 2015
So you suggest using fopen()/fprintf() and fclose() but how I convert to ascii if my data get from edit. I just need the output same as the input from the edit text.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Workspace Variables and MAT Files 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