日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

使用visual studio 2013读取.mat文件

發(fā)布時(shí)間:2025/3/15 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用visual studio 2013读取.mat文件 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

現(xiàn)在有一個(gè)T.mat 文件需要在c++中處理然后以.mat 或是.txt形式返回

T.mat中存儲(chǔ)了十個(gè)cell,每個(gè)cell中會(huì)有一個(gè)不等長(zhǎng)的數(shù)組

1.以下是相關(guān)配置過(guò)程:

參考:http://wenku.baidu.com/link?url=3CiA3T6wtaBEUSJnpvmfmvZzaKXop1Ea68HM-s1S02fMZUm5dhYsqrC4tE4JNjbYbvnflEe7ZaRa5oqCQmNGBvmAi67ZujICsjxXKIuEzC

?

VC++ 包含目錄 添加 D:\Program Files\MATLAB\R2014a\extern\include\win64;D:\Program Files\MATLAB\R2014a\extern\include;

連接器 常規(guī) 附加庫(kù)目錄 D:\Program Files\MATLAB\R2014a\extern\lib\win32\microsoft;D:\Program Files\MATLAB\R2014a\extern\lib\win64\microsoft

鏈接器 輸入 附加依賴項(xiàng) libmat.lib;libmx.lib;libmex.lib;libeng.lib

配置管理器中活動(dòng)解決方案平臺(tái)選擇x64

更改環(huán)境變量path D:\Program Files\MATLAB\R2014a\extern\lib\win64\microsoft;D:\Program Files\MATLAB\R2014a\bin\win64

2.然后是讀入的代碼

//read .mat from matlab #include <iostream> #include <mat.h> #include<iomanip> #include <fstream> #include <vector> using std::vector; int main() {MATFile *pmatFile = NULL;mxArray *pMxArray = NULL, *pMxArray_i = NULL;double *pMx_cell_i = NULL;//讀入.MATpmatFile = matOpen("D:/Program Files/MATLAB/R2014a/work/mywork/test_for_data/mydata1.mat", "r");//std::cout << pmatFile;pMxArray = matGetVariable(pmatFile, "w");//size_t M = mxGetM(pMxArray);//size_t N = mxGetN(pMxArray);//std::cout << N;int num_of_cell{ (int)mxGetNumberOfElements(pMxArray) };std::cout << "the number of the CELL we have got for the T :" << num_of_cell << std::endl;//int A[10];由于數(shù)組 的長(zhǎng)度需要事先給定,所以改用vectorvector<int> V_A;//Matrix<double> A(num_of_cell, 1);for (int i{ 0 }; i < num_of_cell; i++){pMxArray_i = mxGetCell(pMxArray, i);int num_of_cell_i = (int)mxGetNumberOfElements(pMxArray_i);std::cout << "the number of the CELL " << i << " we have got for the T :" << num_of_cell_i << std::endl;double sum_i = 0;for (int j{ 0 }; j < num_of_cell_i; j++){pMx_cell_i = mxGetPr(pMxArray_i);std::cout << std::setw(10) << *(pMx_cell_i + j);sum_i = sum_i + *(pMx_cell_i + j);}std::cout << std::endl;std::cout << "sum " << i << " is " << sum_i << std::endl;//A[i] = sum_i; V_A.push_back(sum_i);// }matClose(pmatFile);//mxFree(pMxArray);//mxFree(pMxArray_i);//mxFree(pMx_cell_i);//寫到e:/data.TXT中 FILE *p=NULL;//if ((p = fopen("e:\\data.txt", "wt")) != NULL)//for (int i = 0; i<10; i++) // fprintf(p, "%d \n", A[i]); //fclose(p);//FILE *p;if ((p = fopen("e:\\data_V.txt", "wt")) != NULL)for (int i = 0; i<num_of_cell; i++)fprintf(p, "%d \n", V_A.at(i));fclose(p); }

?


后記:這里主要還是驗(yàn)證配置的正確性,只進(jìn)行了一個(gè)加和運(yùn)算。

修改:使用vector來(lái)存儲(chǔ)計(jì)算結(jié)果,可以適應(yīng)數(shù)據(jù)的長(zhǎng)度改變。

轉(zhuǎn)載于:https://www.cnblogs.com/simayuhe/p/5246157.html

總結(jié)

以上是生活随笔為你收集整理的使用visual studio 2013读取.mat文件的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。