How do I get each iteration of a for loop into a single row matrix?

조회 수: 2 (최근 30일)
Heath
Heath 2025년 4월 24일
편집: Walter Roberson 2025년 4월 25일
Here I am getting each iteration correctly but I need pmf to be a row matrix with the answers from 0 to max(Data).
function [pmf] = CalcRelFreq(Data);
for range = 0:max(Data)
pmf = [1 ;sum(Data == range)/length(Data)]
end
  댓글 수: 2
James Tursa
James Tursa 2025년 4월 24일
편집: James Tursa 2025년 4월 24일
What is size(Data)? Please provide a small example input and desired output. pmf looks like a column vector, so it is unclear how you want these stacked into a row vector.
Heath
Heath 2025년 4월 24일
편집: Heath 2025년 4월 24일
I actually don't need it to be a row vector a column vector is good but still unsure how to do it
the input is userData which is a 20x1 matrix =
11
17
13
4
12
8
12
10
7
14
12
6
10
14
11
10
10
9
10
13

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2025년 4월 24일
편집: Matt J 2025년 4월 25일
Data=[ 11
17
13
4
12
8
12
10
7
14
12
6
10
14
11
10
10
9
10
13];
pmf=histcounts(Data,0:max(Data)+1)'/length(Data),
pmf = 18×1
0 0 0 0 0.0500 0 0.0500 0.0500 0.0500 0.0500
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

카테고리

Help CenterFile Exchange에서 Continuous Wavelet Transforms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by