필터 지우기
필터 지우기

vector product and sum not working

조회 수: 1 (최근 30일)
Apple
Apple 2017년 2월 8일
댓글: James Tursa 2017년 2월 8일
I have a function that I have created that does a lot of calculations with a single random vector.
function [ vec_below_12_5, new_vec, rev_vec, difference ] = calc( vec )
vec_below_12_5=sum(vec>=1 & vec<=12.5);
%counts vectors between 1 and 12.5;
new_vec=vec.^min(vec);
%vector to the power of the lowest element;
rev_vec = fliplr(vec);
%flips vector
vecprod = prod(vec);
vecsum = sum(vec);
difference = vecprod-vecsum;
%difference between the product and sum of a vector;
histogram(vec);
ylabel('frequency');
xlabel('number');
legend('output arguments');
title('graph for vec');
%creates histogramm for vectors
end
however, when I run it in the command window it doesn't give me a single value for the difference vecprod-vecsum it simply copies the original vector. I couldn't find the problem so I ran it as a separate function and it gives me the single value.
does anyone know why it won't run in the above function but will in a separate function.
  댓글 수: 1
James Tursa
James Tursa 2017년 2월 8일
Please show us the exact code you use to call the function. I.e., give us the arguments and the calling syntax you use.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by