필터 지우기
필터 지우기

Help with updating array within function

조회 수: 8 (최근 30일)
Marios Christofides
Marios Christofides 2020년 8월 9일
답변: Monisha Nalluru 2020년 8월 14일
For my homework I have to write a function to update an array after they don't get enough votes, but I'm not sure how to update the array from [N × c] to [N × c − 1].
function votes = removeCandidate(votes,losingCandidate)
[votes,I] = max(votes1);
nv = length(votes1);
if v1/nv > 0.5
losingCandidate = 1;
end
end
  댓글 수: 1
dpb
dpb 2020년 8월 9일
One can either remove elements (full row or column if 2D) by assigning the [] (empty) array to the selected array subscripts or alternatively save all rows(/columns) except the unwanted row(s)/column(s).
The actual definition of what your function is to do and return so can't comment much about that part...

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

답변 (1개)

Monisha Nalluru
Monisha Nalluru 2020년 8월 14일
You may refer to this following documentation:
% a is array
a(end,:)=[] % delete last row
a(:,end)=[] %delete last column
Since in your example aray dimwnesion is change from NXC to NXC-1 you need to delete a column in the array

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by