Author Topic: i/o  (Read 3346 times)

Offline dazjaz

  • Newbie
  • *
  • Posts: 1
  • Matlab Forum
    • View Profile
i/o
« on: September 26, 2010, 10:28:21 AM »
need help loading data from chirp example 1 saved to file using save( 'data.txt', '-ascii) to array in c using fread().
 
t=0:0.001:2;
y=chirp(t,0,1,150);
spectrogram(y,256,250,256,1E3);
save('data.txt','-ascii');
 
thanks
 

Offline 50dolars

  • Newbie
  • *
  • Posts: 7
  • Matlab Forum
    • View Profile
Re: i/o
« Reply #1 on: September 29, 2010, 07:00:09 AM »
what do you need to help mode ?

Offline Clint

  • Newbie
  • *
  • Posts: 3
  • Matlab Forum
    • View Profile
Re: i/o
« Reply #2 on: December 03, 2011, 11:51:16 AM »
Whenever something fails while reading a file the error flag is set to true, after that all subsequent read will fail. so when you find some error while reading and come over it reset the error flag to false before you proceed.
 
 
[size=0pt]1[/size][size=0pt][/color][/size][size=0pt][/color]2[/size][size=0pt][/color][/size][size=0pt][/color]3[/size][size=0pt][/color][/size][size=0pt][/color]4[/size][size=0pt][/color][/size][size=0pt][/color]5[/size][size=0pt][/color][/size][size=0pt][/color]6[/size][size=0pt][/color][/size][size=0pt][/color]7[/size][size=0pt][/color][/size][size=0pt][/color]8[/size][size=0pt][/color][/size][size=0pt][/color]9[/size][size=0pt][/color][/size][size=0pt][/color]10[/size][size=0pt][/color][/size][size=0pt][/color]11[/size][size=0pt][/color][/size][size=0pt][/color]12[/size][size=0pt][/color][/size][size=0pt][/color]13[/size][size=0pt][/color][/size][size=0pt][/color]14[/size][size=0pt][/color][/size][size=0pt][/color]15[/size][size=0pt][/color][/size][size=0pt][/color]16[/size][size=0pt][/color][/size][size=0pt][/color]17[/size][size=0pt][/color][/size][size=0pt][/color]18[/size][size=0pt][/color][/size][size=0pt][/color]19[/size][size=0pt][/color][/size][size=0pt][/color]20[/size][size=0pt][/color][/size][size=0pt][/color]21[/size][size=0pt][/color][/size][size=0pt][/color]22[/size][size=0pt][/color][/size][size=0pt][/color]23[/size][/color][/size]
[/t][/t]  [size=0pt][/color]// clearing errors[/size]
[size=0pt][/color]#include <iostream>[/size]
[size=0pt][/color]#include <fstream>[/size]
[size=0pt][/color]using[/size][size=0pt][/color]namespace[/size] std;

[size=0pt][/color]int[/size] main () {
  [size=0pt][/color]char[/size] buffer [80];
  fstream myfile;

  myfile.open ([size=0pt][/color]"test.txt"[/size],fstream::in);

  myfile << [size=0pt][/color]"test"[/size];
  [size=0pt][/color]if[/size] (myfile.fail())
  {
    cout << [size=0pt][/color]"Error writing to test.txt\n"[/size];
    myfile.clear();
  }

  myfile.getline (buffer,80);
  cout << buffer << [size=0pt][/color]" successfully read from file.\n"[/size];

  [size=0pt][/color]return[/size] 0;
}
 

Matlab and SimuLink Development Forum

Re: i/o
« Reply #2 on: December 03, 2011, 11:51:16 AM »