From ff7b047dd550fbd99a55408f3406664a6df39287 Mon Sep 17 00:00:00 2001 From: Mieszko Makuch Date: Thu, 5 Dec 2024 20:48:11 +0900 Subject: [PATCH] Add original basicVectorOperations.m --- basicVectorOperations.m | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 basicVectorOperations.m diff --git a/basicVectorOperations.m b/basicVectorOperations.m new file mode 100644 index 0000000..5a9b980 --- /dev/null +++ b/basicVectorOperations.m @@ -0,0 +1,44 @@ +% ----------------- +% Copyright © 2019 ACK Cyfronet AGH, Poland. +% +% This work was partially funded by EPOS Project funded in frame of PL-POIR4.2 +% ----------------- + +function [out_vector]=basicVectorOperations(in_vector, numerator, denominator, k, operation_type) +%% BASICVECTOROPERATION Tool for performing simple operations on a given number vector +% +% Input Arguments: +% +% in_vector - input vector +% +% numerator, denominator, k - scalar number - operands of the operation to be performed on the vector +% +% operation_type - name of operation to be performed on vector +% +% Output Arguments: +% +% out_vector - output vector that is the result of the operation +% + + switch operation_type + case {'^', 'POWER'} + if(isempty(denominator)) + denominator = 1; + end + out_vector = in_vector .^ (numerator/denominator); + case {'FILL_FROM_INDEX'} + if(k>length(in_vector)) + error(['Index out of bound. Vector length is: %d, but index is %d'], length(in_vector), k); + else + out_vector = [in_vector(1:k) zeros(1,length(in_vector)-k)]; + end + case {'FILL_TO_INDEX'} + if(k>length(in_vector)) + error(['Index out of bound. Vector length is: %d, but index is %d'], length(in_vector), k); + else + out_vector = [zeros(1,k) in_vector(k+1:length(in_vector))]; + end + otherwise + error(['unsupported operation: "' operation_type '"']); + end +end \ No newline at end of file