problem with importing data from matlab to text file
2 次查看(过去 30 天)
显示 更早的评论
Hello
I managed to read the pixel data for a bitmap (24 bit) and got the individual RGB values in the form of arrays for every pixel. I am trying to import this data for use in an Arduino sketch. final task is to use these individual arrays of RGB and display the bitmap on a LED matrix. I started with trying make a text file for each of these individual array. The problem is this:
Used all functions - dlmwrite, xlswrite, fprintf - but in all the cases, the text file being created wraps the whole array data resulting in a jumble. The array size is 267X400. On importing, after few columns, the data starts wrapping. I removed the Word wrap from text file, did everything but simply cannot understand why exactly the data is coming jumbled. The whole data is like a big long paragraph. And the only good thing is that on writing it to an excel file, I get it nicely in the specified rows and columns, but when I try saving excel file data to text file, the same problem occurs and I do not know yet whether I can pass this excel data directly to arduino....so thats why trying for a text file.
Can someone please help me with this. I am completely lost. Any assistance would be greatly appreciated.
Thanks!
0 个评论
采纳的回答
Guillaume
2016-4-6
From your description, it looks like the problem is with the way you view the text file, not with the way it saved. What program are you using to view the text file? Hopefully not notepad which is useless for that.
You can view the file with the matlab editor, or any of the many free text editors available on the net. I use notepad++, but anything slightly more advanced than notepad should be good enough.
2 个评论
Guillaume
2016-4-7
The format string is fairly simple, it just replicates '%u\t' (prints number as unsigned integer followed by a tab) as many times as there are columns in R. It follows that with a newline at the end of each row. R has to be transposed as it is passed to fprintf according to its linear indices. Otherwise, it would print the columns of R as rows in the file.
While it works (assuming you want to save your numbers as integer), you could simply replace it (together with the fopen and fclose calls) with:
dlmwrite(filename, R, 'delimiter', '\', precision, '%u');
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!