How to graph data in cells?

3 ビュー (過去 30 日間)
Hilary Kada
Hilary Kada 2020 年 6 月 28 日
コメント済み: Turlough Hughes 2020 年 6 月 29 日
Hello!
I wrote a function called transformdata and I recently got some help being able to run that function for all the csv files I have in a folder (https://au.mathworks.com/matlabcentral/answers/555148-how-to-run-a-code-for-all-files-in-a-folder?s_tid=mlc_ans_email_ques). The output matrix of this function is three columns; the first is time, the second is acceleration and the third is velocity. Once I run the function on all the csv files the output is a cell, which contains the output matrix from the function for all the different csv files. Is there a way to graph all the output matricies from the cell on one graph, using the time column from the output matricies as the x-axis and then plotting the acceleration and velocity?
Am a real matlab beginner so any help would be great!
Thanks!
  2 件のコメント
Turlough Hughes
Turlough Hughes 2020 年 6 月 28 日
Hi Hilary, could you attach the cell array as a .mat file. To save the variable, right click on it in the Workspace window and click Save as...
Also, as a beginner I recommend that you spend some time looking at the introductory onramp course for MATLAB.
Hilary Kada
Hilary Kada 2020 年 6 月 28 日
編集済み: Hilary Kada 2020 年 6 月 28 日
Sure! Currently I've only been running this entire thing for a small sample of the data I have (in reality each data set is like 4000+ rows long and there's about 40+ sets of data), and so not all the matricies in the cell array will be the same size when I run it for the real data.
Haha yes thanks, I'll give that a go!

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

採用された回答

Turlough Hughes
Turlough Hughes 2020 年 6 月 28 日
編集済み: Turlough Hughes 2020 年 6 月 28 日
Your data has an empty cell in it so the first step here is to remove that
ToBeGraphed(cellfun(@isempty,ToBeGraphed))=[]; % remove empty cells
You can then graph as follows:
figure(), hold on
cellfun(@(x) plot(x(:,1),x(:,2)),ToBeGraphed)
ylabel('Acceleration')
yyaxis right % or replace with: figure(), hold on
cellfun(@(x) plot(x(:,1),x(:,3)),ToBeGraphed)
ylabel('Velocity')
xlabel('Time')
Replace the 4th line as indicated above if you'd like to have velocity and accelerations on seperate figures.
  2 件のコメント
Hilary Kada
Hilary Kada 2020 年 6 月 29 日
Oh my god thank you so much that's exactly what I needed! You're a damn lifesaver and straight up saved me like a billion hours of manually graphing each data set on excel. Thanks!
Turlough Hughes
Turlough Hughes 2020 年 6 月 29 日
No problem 😊

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by