Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Need help, Why is Matlab not writing to file?

  1. Mar 10, 2010 #1

    f = input('Enter the force applied in lbs: ');
    p_c = input('Enter point closest to pivot: ');
    p_f = input('Enter point farthest from pivot: ');
    filename = input('name of file is: ','s');
    points = input(' # of points to calculate: ');

    x = [p_c;rand(points,1)*p_f-p_c+p_c;p_f];
    y = sort(x);
    pos = find(y<p_c);
    pos1 = find(y>p_f);
    y(pos) = [];
    y(pos1) = [];

    %disp(y) points

    M = y*f;

    %disp(M) moment

    final = [y,M];

    Mo = fopen([filename,'_',f,'_',points,'.txt'], 'w');

    %fid = fopen(string, option)


    fprintf(Mo, 'ID:\t%s\nF:\t%2.2f\n point closest:\t%2.3f\n point farthest:\t%2.3f...\n',filename,f,p_c,p_f);
    fprintf(Mo, ' points\t moment\n');
    fprintf(Mo, '%.2f\t.2f',y,M);

    Your thoughts would be helpful because I don't see why this isn't working
  2. jcsd
  3. Jun 5, 2010 #2
    The variables f, and points (which are of type double), are used to generate you file name without being converted to string.
    Try, using num2str function, for example
    Code (Text):
    Mo = fopen([filename,'_',num2str(f),'_',num2str(points),'.txt'], 'w');
    Also, you might want to have a closer look at:
    think, it's missing a % after \t.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Threads - Need help Matlab Date
Matlab Help needed to fix a matlab code Nov 8, 2017
Need help with integral Dec 23, 2015
Need help in MATLAB Oct 10, 2013
Need help plotting Fourier series in matlab Sep 24, 2013
Need help with Matlab's Mapping Toolbox Feb 10, 2013