NEED HELP! in load a text file containing the first one million digits of Pi.

4 ビュー (過去 30 日間)
EDEN
EDEN 2019 年 3 月 14 日
コメント済み: Stephen23 2019 年 3 月 14 日
Hi friends, I have a problem loading a text file containg the frist one million digits of number Pi.
Any one who can help i really need help it is urgent!!!.
  5 件のコメント
Adam Danz
Adam Danz 2019 年 3 月 14 日
編集済み: Adam Danz 2019 年 3 月 14 日
Rather than loading the digits from the text file, couldn't you get them directly from within Matlab?
p = sym(pi);
piVpa = vpa(p,1000001);
piChar = char(piVpa);
% put all decimal places into a vector (might take several seconds)
pidp = str2double(cellstr(piChar(3:end)'));
UPDATE: when compared with Stephen Cobeldick's solution using isequal(vec, pidp), the results are the same. However, Stephen's solution is much faster. My solution would be a good plan-b if you don't have a text file available.
EDEN
EDEN 2019 年 3 月 14 日
First thank you for your time friends, i have attached the file here. i used the command 'load' but it doesnt help, if u can help me load that file in matlab i would really appreciated.
Thank you so much for helping me.

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

採用された回答

Stephen23
Stephen23 2019 年 3 月 14 日
編集済み: Stephen23 2019 年 3 月 14 日
This code imports all of the digits in around one second:
>> fid = fopen('data.txt','rt');
>> vec = fscanf(fid,'%1d');
>> fclose(fid);
>> numel(vec)
ans = 1000000
>> vec(1:10) % first ten digits
ans =
3
1
4
1
5
9
2
6
5
3
>> vec(end-9:end) % last ten digits
ans =
0
5
7
7
9
4
5
8
1
5
  3 件のコメント
EDEN
EDEN 2019 年 3 月 14 日
Thank you so much..... it works!!!
Stephen23
Stephen23 2019 年 3 月 14 日
@EDEN: then don't forget to accept my answer!!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by