C++ to matlab(m-file) without mex
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a C++ code:
#include <iostream>
#include <fstream>
#include <iomanip> // std::setfill, std::setw
using namespace std;
int main()
{
int i,j;
ofstream outfile;
outfile.open("testText.txt", ios::app);
outfile<< setfill('0');
for(i=0;i<2;i++)
{
for(j=0;j<12;j++)
{
outfile<<"XYZ"<<setw(2)<<i<<setw(2)<<j<<"\n";
}
outfile<<"\n";
}
outfile.close();
return(0);
}
Which will generate a text file like:
XYZ0000
XYZ0001
XYZ0002
XYZ0003
XYZ0004
XYZ0005
XYZ0006
XYZ0007
XYZ0008
XYZ0009
XYZ0010
XYZ0011
XYZ0100
XYZ0101
XYZ0102
XYZ0103
XYZ0104
XYZ0105
XYZ0106
XYZ0107
XYZ0108
XYZ0109
XYZ0110
XYZ0111
Need to create same output using matlab code.
Main problem:
setfill() alternative in matlab?
setw() alternative in matlab?
how
outfile<<"XYZ"<<setw(2)<<i<<setw(2)<<j<<"\n";
line can be replaced?
setw(): used to set field width of the next variable
setfill(): used to set fill character, what should be used to fill the width in setw.
Really need some help. Thanks in advance.
1 Kommentar
James Tursa
am 16 Mär. 2015
Bearbeitet: James Tursa
am 16 Mär. 2015
Duplicate Question. Please delete.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!