MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   [MATLAB混合编程] 如何从vc中将此txt文件读出来 (https://www.labfans.com/bbs/showthread.php?t=8754)

云龙九现 2009-06-01 16:03

如何从vc中将此txt文件读出来
 
最近在对编写的程序进行分析的时候,碰到了一个问题,需要将matlab的workspace中的
数据格式化写入txt文件,然后由vc将其读出来。但在用vc读的时候出现了一些问题,现在寻求解决方法,现在的问题是:matlab写txt文件的程序没问题,但vc读的程序有问题。希望哪位大侠帮帮忙指点指点
---------------------------------matlab写txt文件的程序---------------------
clc
clear
x=randn(8,8);
x=[1:8;x];
x=x';
fid=fopen('randata.txt','wb');
fprintf(fid,'%12.10f %12.10f %12.10f %12.10f %12.10f %12.10f %12.10f %12.10f %12.10f\n',x);
fclose(fid);
-----------------------------vc读txt文件的程序-----------------------------
#include "stdafx.h"
#include <iostream.h>
#include <stdio.h>

void main(int argc, char* argv[])
{
FILE *fp;
double randata[9][8];
fp=fopen("randata.txt","rb");
if(fp==NULL)
printf("file not open\n");
for(int i=0;i<8;i++)
{
fscanf(fp,"%12.10f %12.10f %12.10f %12.10f %12.10f %12.10f %12.10f %12.10f %12.10f\n",&randata[i][0],&randata[i][1],&randata[i][2],&randata[i][3],&randata[i][4],&randata[i][5],&randata[i][6],&randata[i][7],&randata[i][8]);
printf("%f %1f %f %f %f %f %f %f %f\n",randata[i][0],randata[i][1],randata[i][2],randata[i][3],randata[i][4],randata[i][5],randata[i][6],randata[i][7],randata[i][8]);
}
fclose(fp);
}

elefly 2009-06-02 11:22

回复: 如何从vc中将此txt文件读出来
 
出了什么问题?你要读的是什么东西?


所有时间均为北京时间。现在的时间是 14:19

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.