Reading and calculations with a csv file with a pair of numbers in each cell

1 回表示 (過去 30 日間)
Saba Malik
Saba Malik 2016 年 2 月 18 日
編集済み: Jan 2016 年 2 月 18 日
I was wondering if anyone could help me with the following problem :
I need to read data from a .csv file into MATLAB so that I can work with it and perform calculations . The numbers in each cell are in the following format : {0.003336 , 0.023000}. I'm working with 128 x 128 cells in a spreadsheet . Functions such as csvread aren't working for me possibly because there are curly brackets as well as numbers in each cell ?
Ideally I would like to store the first number of each pair as the (1,1) element of a 2x2 matrix M and the second number as the (2,2) element in M . But I need the data to be read first !
Any help and advice would be much appreciated !
Saba

採用された回答

Jan
Jan 2016 年 2 月 18 日
編集済み: Jan 2016 年 2 月 18 日
Would this work:
fid = fopen(FileName, 'r');
if fid == -1, error('Cannot open file: %s', FileName); end
Data = fscanf(fid, '{%g, %g}', 128*128); % Edited: fid inserted
fclose(fid);
The wanted output format is not clear: What should the other 2 elements of M contain and how do you want to store the 128*128 M's?
If you append an example file or at least some lines of the file as text, testing a suggestion would be easier.
  3 件のコメント
Saba Malik
Saba Malik 2016 年 2 月 18 日
sorry i realise the file i attached before was the excel version ; here's the csv
Jan
Jan 2016 年 2 月 18 日
編集済み: Jan 2016 年 2 月 18 日
I forgot the fid in the fscanf call. The code ist fixed. My question about the M-matrix: You get 128*128 M-matrices, when I understand it correctly. How do you want to store them? As a {128 x 128} cell matrix?
There is no attached csv file.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by