read matrix from .txt
显示 更早的评论
hello, can anyone tell me what do i have to do to read this matrix saved on a.txt file?
1 2 3 4
5 6 7 8
9 10 11 12
thx :)
采纳的回答
M=dlmread('filename.txt')
12 个评论
hi azzi! thx for the help! but is comining back this:
*>> M=dlmread('matlab1.txt')
Error using dlmread (line 139)
Mismatch between file and format string.
Trouble reading number from file (row 1u, field 1u) ==> ÿþ1*
Azzi Abdelmalek
2013-10-20
编辑:Image Analyst
2013-10-20
From your post, your file contains a matrix of numbers, is it true? Maybe your file contains also characters.
yes! i made that matrix on excel and save it to .txt
only contain this:
1 2 3 4
5 6 7 8
9 10 11 12
the conversion of .xls to .txt maded by excel add other things? if i open it with the notepad i see the matrix of numbers that i wrote and nothing else
1 2 3 4
5 6 7 8
9 10 11 12
You can import your data from your Excell file with xlsread. If your txt file contains only numbers, the code should work.
but my homework asked me to read .txt haha :(
Alternatively, try importdata() or save from Excel as a CSV file instead.
Open your file with e.g. the notepad or MATLAB editor, and copy/paste the content here, using {}Code formatting.
Or better yet, just attach the whole file with the paperclip icon.
thx man :)
Ok, there are special characters in your file, so the issue is probably the way you saved it with Excel. Try exporting the Excel file as CSV (Comma Separated Values) even if you name the file with a .txt extension.
thx mate!! works fine now with that comma thing :)
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Spreadsheets 的更多信息
标签
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
