vector arithmetic and relational addressing,, how to create 2nd and 3rd column?

10 ビュー (過去 30 日間)
Jes
Jes 2021 年 11 月 20 日
回答済み: Pranjal Kaura 2021 年 11 月 23 日
nElements = round(20+30*rand(1));
x = -50 + 100*rand(nElements,1);
[y, z , count] = vectorFun(x)
function [y, z , count] = vectorFun(x)
%Enter the commands for your function below. Be sure to assign values
%to each of the output variables defined in the function command on line 1.
y = linspace(min(x),max(x),length(x))';
z =

回答 (1 件)

Pranjal Kaura
Pranjal Kaura 2021 年 11 月 23 日
Hey Jeson,
You can refer to the following code snippet. You can use the 'nnz' function to compute the final value i.e. count.
function [y, z , count] = vectorFun(x)
%Enter the commands for your function below. Be sure to assign values
%to each of the output variables defined in the function command on line 1.
y = linspace(min(x),max(x),length(x));
%syntax '.*' or './' is used to compute element vise multiplication or
%element vise division
z = x.^2./(2*y);
% Use the nnz function to compute the value of count. Remember you can directly compare 2
% vectors using the comparator operators like '<' and '>' and these will
% return logical arrays.
% count =
end
Hope this helps!

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by