I'm using textscan to read in a csv file, but when I check the variable its incorrect

3 ビュー (過去 30 日間)
im trying to read in a csv file(attached) using the code below, but then when i click on the variable from the workspace I dont get the correct cell array (i attached a screenshot of what appears when i select the variable from the workspace). I got this code from the internet and im doing it in the same way, but it still doesnt work.
fid = fopen('NaiveBankData.csv');
readNaiveBankData= textscan(fid, '%d %f', 'HeaderLines',1, 'Delimiter', ',');

採用された回答

Image Analyst
Image Analyst 2021 年 12 月 2 日
Can you try importdata(), readmatrix(), or csvread() instead?
  5 件のコメント
Image Analyst
Image Analyst 2021 年 12 月 2 日
Well it looks like you got it figured out with Star's code. That's good because there was no way I was going to try to guess what was in 'NaiveBankData.csv', which you refused to upload.
Tariq Hammoudeh
Tariq Hammoudeh 2021 年 12 月 2 日
im sorry about that i didnt realize the screenshot didnt show the entire thing.
I uploaded the csv file, can i please get help with the other part, because i cant fugure out how to make "ismember" work

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2021 年 12 月 3 日
編集済み: Image Analyst 2021 年 12 月 3 日
Try this:
t = readtable('NaiveBankData.csv')
[rows, columns] = size(t);
% Convert Balance column to double
balances = zeros(rows, 1);
for row = 1 : rows
thisString = t.Balance{row};
% Get rid of commas and pound symbol.
thisString = strrep(thisString(2:end), ',', '');
balances(row) = str2num(thisString);
end
tB = table(balances(:), 'VariableNames',{'dblBalance'});
t = [t, tB]
You'll see
t =
5×3 table
AccountNumber Balance dblBalance
_____________ _____________ __________
105 {'£6,327.15'} 6327.15
234 {'£203.54' } 203.54
576 {'£52.45' } 52.45
594 {'£5,489.00'} 5489
876 {'£1,245.80'} 1245.8

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by