Creating Histogram using .mat file

Hello,
I am trying to create a histogram. I used a .mat file to create a 1x5000 structure. I am trying to plot only 1000 out of the 5000, so I call 'a' and set the length to 1000 in a for loop, but it says it is only plotting one data point instead of them all. Any idea what I am doing wrong? Thanks!

2 件のコメント

Stephen23
Stephen23 2020 年 8 月 18 日
1000 is a scalar number, so length(1000) is one, so your loop will iterate exactly once.
Sclay748
Sclay748 2020 年 8 月 18 日
ahh I thought if I changed x from a(i).time; to a(1).time; then that would be scalar and only print time once at the first row. Thought I was safe putting it in the length.
How would I fix this so it isn't scalar and includes all 1000 points?

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

 採用された回答

Cris LaPierre
Cris LaPierre 2020 年 8 月 18 日

1 投票

I suspect your don't really want to create 1000 histograms. You don't need a for loop.
Try
histogram([a(1:1000).time])

7 件のコメント

Sclay748
Sclay748 2020 年 8 月 18 日
Hi Cris, I got an error for too many input arguments.
Cris LaPierre
Cris LaPierre 2020 年 8 月 18 日
Did you include the square brackets around the structure?
We don't have your data, so I created a simple test case:
a(1).t=5;
a(2).t=0;
a(3).t=5
histogram([a(1:3).t])
What version of MATLAB are you using?
Sclay748
Sclay748 2020 年 8 月 18 日
I did, and 2020a
Sclay748
Sclay748 2020 年 8 月 18 日
編集済み: Sclay748 2020 年 8 月 18 日
The data is super long, but there is 5000 rows, and two columns.
1 column is numbered 1-5000, and second colomn has a single time (in miliseconds), and the field is called time.
Sclay748
Sclay748 2020 年 8 月 18 日
wait, now it is working. I was trying to do
histogram([a(1:1000).time/1e3])
to get seconds instead of miliseconds, but the code wasnt liking it.
Cris LaPierre
Cris LaPierre 2020 年 8 月 18 日
I think you'd have to do it like this:
histogram([a(1:1000).time]/1e3)
Sclay748
Sclay748 2020 年 8 月 18 日
ahh that did it, thank you!

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

その他の回答 (0 件)

カテゴリ

タグ

質問済み:

2020 年 8 月 18 日

コメント済み:

2020 年 8 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by