Export of string into ASCII file

7 次查看(过去 30 天)
Pap
Pap 2011-4-4
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

回答(1 个)

Walter Roberson
Walter Roberson 2011-4-4
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 个评论
Pap
Pap 2011-4-5
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by