You are given the following vector: A = [18 334 98 73 129 7 62 9 212 55 3] Write
ID: 675204 • Letter: Y
Question
You are given the following vector: A = [18 334 98 73 129 7 62 9 212 55 3] Write a function that has 2 inputs: The cut-off, C, and An array, A; and 3 outputs: A vector of zeros and ones (1's represent values greater than P and 0's represent values less than or equal to C), An array of the indices of the elements in A that are greater than C A total of how many values are above the threshold. For example if the cutoff point is 17, the script file should return the following vector. Example = [1 1 1 1 1 0 1 0 1 1 0] Above_Cutoff = [1 2 3 4 5 7 9 10] Use the vector A given above and show the following cases:Explanation / Answer
//Test.m
clear all
clc
close all
A=[18 334 98 73 129 7 62 9 212 55 3];
C=17;
[V01,Index,Total]=SampleFunction(C,A)
C=110;
[V01,Index,Total]=SampleFunction(C,A)
C=58;
[V01,Index,Total]=SampleFunction(C,A)
C=19;
[V01,Index,Total]=SampleFunction(C,A)
//Function
function [V01, Index, Total] = SampleFunction( varargin)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
C = varargin{1};
A = varargin{2};
V01= A >= C;
Index=[];
Count=1;
Total=0;
for I=1:length(A)
if A (I) >= C
Index(Count)=I;
Count=Count+1;
Total=Total+ A(I);
end
end
end
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.