How do I subplot from a large file? Note..any .txt file of any large figures can be given. So please solve generally.
1 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/613885/image.png)
I have to plot time against distance. But any .txt file will be given which may contain any number of datas. How do I subplot them in a loop?
6 个评论
Rik
2021-5-11
It is good that you showed the code you tried, however, without a better description (even with MS Paint) of the intended result, it is hard to help you. Also, you should post your code as code, instead of a screenshot.
回答(1 个)
Walter Roberson
2021-5-11
You could calculate N more cleanly as
N = size(r, 1);
T and c and r will each be a single column.
You take the number of rows in r, and take the square root of it, and want to do subplots; if everything works out and the number of input rows was a square integer, you would end up with a number of subplots equal to the number of rows.
In each iteration, you go to plot one column . But r and c only have one column, so the second iteration would produce an error.
You should not be calculating
cols = ceil(n./rows)
Suppose for example there were 50 rows to start, so N = 50, so rows = floor(sqrt(50)) so rows = 7. Then n = [50 1] (because size(r(:,end)) is going to be a vector of length 2, the second element of which is 1). [50 1]./7 is [7.14<etc>, 0.14<etc>]. ceil([7.14<etc>, 0.14<etc>]) is [8 1]. But using [8 1] as a subplot bound is an error. You should be using cols = ceil(N./rows)
Now you go to iterate i = 1 : N and you go to plot() one column each time. But there is only one column... You could switch to using i as the row index, but if you did that you would be plotting only one point per subplot.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!