Borrar filtros
Borrar filtros

Export of string into ASCII file

7 visualizaciones (últimos 30 días)
Pap
Pap el 4 de Abr. de 2011
Hello,
% I have imported some data as txt from an ASCII file (stocks.txt)
Since I created a new variable 'Trade' with its values resulted by a code 'buysell' I want to extract it as the final column in my original ASCII. thus I create 'stocks2.txt' as below:
fid = fopen('ex2.txt','wt');
% Make output string by appending trade decision
outstr = strcat(txt{1},[' Trade';buysell]);
% Write out
fprintf(fid,'%s\n',outstr{:}); fclose(fid);
% Now I try to open (even outside Matlab) the ASCII 'stocks2.txt' but is completely blank.
The new string (outstring)is as expected, but is there any way to export it in a new txt file?
I even tried a simple Copy/ Paste to a new txt file but it doesn't work.
Sorry for the naiveness of the question but as a new user I am slightly confused even with simple applications.
Many thanks,
Panos

Respuestas (1)

Walter Roberson
Walter Roberson el 4 de Abr. de 2011
What data class is buysell ? If it is a character array and txt{1} is a string, then the result of the strcat() is going to be a character array instead of a cell array.
There have been cases known where a file closed in Matlab does not become immediately available outside of Matlab. I do not know the solution to that. Which Matlab version are you using?
  1 comentario
Pap
Pap el 5 de Abr. de 2011
The codes are:
%Get prices from imported data
Price = data{4};
% Determine which stocks to buy
buy = [true;diff(Price)>=0];
idx = find(~diff(Price));
buy(idx+1) = buy(idx);
% Make string of trade decision
buysell = cellstr(repmat(' Sell',size(Price)));
buysell(buy) = {' Buy'};
I use MatlabR2010a. Is something that I can do?

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by