Plot did not work
情報
この質問は閉じられています。 編集または回答するには再度開いてください。
古いコメントを表示
M 204 20795 20795 3000 0 16067 16066 3000 0 0 0 6000 0
M 524 20795 20794 3000 0 16067 16066 3000 0 0 0 6000 0
M 735 20795 20795 3000 0 16067 16066 3000 0 0 0 6000 0
M 995 20795 20795 3000 0 16067 16067 3000 0 0 0 6000 0
M 995 20795 20795 3000 0 16067 16067 3000 0 0 0 6000 0
M 1233 20795 20795 3000 0 16067 16067 3000 0 0 0 6000 0
M 1499 20795 20795 3000 0 16067 16067 3000 0 0 0 6000 0
M 1763 20795 20795 3000 0 16067 16067 3000 0 0 0 6000 0
This is the data file. I want to take out 3rd column and 7th column from the file and plot them as well. I write down the code in matlab.
f = fopen('robot4_motors.txt');
plot(f(:, 3), f(:, 7))
But the code did not work .
Throws error Index in position 2 exceeds array bounds (must not exceed 1).
1 件のコメント
madhan ravi
2018 年 10 月 5 日
編集済み: madhan ravi
2018 年 10 月 5 日
Can you upload your text file(robot4_motors.txt)?
回答 (2 件)
Steven Lord
2018 年 10 月 5 日
1 投票
The output from fopen is not the data stored in the file. It is a file identifier that you can pass into other functions to allow them to access the data stored in the file.
I'd probably use the readtable or textscan functions to read the data from the file into memory. See the documentation, doc readtable or doc textscan, for information on how to call them and examples you copy into your code and modify to adapt to your data file. Then you can plot the data you read in.
0 件のコメント
Star Strider
2018 年 10 月 5 日
Your ‘f’ matrix appears to be a cell array.
If so, and if I am correct in characterising it here, this will run without errors, although (with the data you posted) will not provide an interesting plot:
f = {{'M' 204 20795 20795 3000 0 16067 16066 3000 0 0 0 6000 0
'M' 524 20795 20794 3000 0 16067 16066 3000 0 0 0 6000 0
'M' 735 20795 20795 3000 0 16067 16066 3000 0 0 0 6000 0
'M' 995 20795 20795 3000 0 16067 16067 3000 0 0 0 6000 0
'M' 995 20795 20795 3000 0 16067 16067 3000 0 0 0 6000 0
'M' 1233 20795 20795 3000 0 16067 16067 3000 0 0 0 6000 0
'M' 1499 20795 20795 3000 0 16067 16067 3000 0 0 0 6000 0
'M' 1763 20795 20795 3000 0 16067 16067 3000 0 0 0 6000 0}};
x = [f{:}{:,3}]
y = [f{:}{:,7}]
plot(x, y, '-p')
Experiment to get the result you want.
0 件のコメント
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!