Question

I have created a function (lets call it function A) in MATLAB that uses 'for loop'...

I have created a function (lets call it function A) in MATLAB that uses 'for loop' to create a 3*4 matrix. I am creating another MATLAB function (lets call it function B) that has absolutely no relation with function A but needs to use the matrix from function A.

How do I call only the matrix from function A to function B such that as this matrix changes in function A it triggers corresponding changes in function B as well?

Is there a way I can save the matrix in function A after the 'for loop' such that I can call the matrix anywhere else I choose?

Thanks

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Lets take an example that You have created a matrix 'Y' in function A. You can take it as return

syntax

function [Y] = Function_A()

%% function body%%

end

then on main window you can write

C=Function_A();

so the matrix on which you have performed operation will be returned by Function_A and will get store in C;

now you can pass this matrix in Function_B by writing

Function_B(C);

for full example i am creating two function with same name as given in the problem

function[Y]= Function_A()
Y=eye(4);
end

above created a function with name Function_A which create a matrix Y which is 4*4 identity matrix;

and below is the function with name Function_B which will then calculate the determinent of that matrix and store it in 'r' and then return it. below a picture attached see how to use it

function[r]= Function_B(C)
r=det(C);
end

Hope u understood it

Please dont forget to like❤️

Add a comment
Know the answer?
Add Answer to:
I have created a function (lets call it function A) in MATLAB that uses 'for loop'...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In matlab I have created the following function function [distance, xplot, yplot] = Cannon_lab8(V, theta) %...

    In matlab I have created the following function function [distance, xplot, yplot] = Cannon_lab8(V, theta) % the function calculates the distance a projectile travels when shot from % a cannon given initial velocity and theta. g = -9.81; % m/s^2 k = 0.35; % drag coefficient Vx = V*cos(theta); Vy = V*sin(theta); dt = 0.01; % seconds x = 0; y = 0; xplot(1) = 0; yplot(1) = 0; i = 2; while y >= 0 ax = -k*Vx; ay...

  • using this array I need to create a user created function in Matlab that does the...

    using this array I need to create a user created function in Matlab that does the following I have this so far but I'm so lost could you please make this with comments on what the codes do Lure dueren suuj (COM 94 97 95 19 91 88 95 87 90 72 78 60 98 87 81 79 76 69 192 80 77 73 78 70 80 89 81 186 94 901 b. Find the lowest grade in Math subject...

  • In matlab I have created the following function that calculates the distance a projectile travels when...

    In matlab I have created the following function that calculates the distance a projectile travels when shot from a cannon given initial velocity and theta. function [distance, xplot, yplot] = Cannon_lab8(V, theta) g = -9.81; % gravity m/s^2 k = 0.35; % drag coefficient Vx = V*cos(theta); %velovity in x-direction Vy = V*sin(theta); %velovity in y-direction dt = 0.01; % seconds, time step x = 0; y = 0; xplot(1) = 0; yplot(1) = 0; i = 2; while y...

  • I have a simple C++ RPC that lets you have remote class instances that support live...

    I have a simple C++ RPC that lets you have remote class instances that support live members (data structures) update as well as method calls. For example I had a class declared like this (pseudocode): class Sum{ public:     RPC_FIELD(int lastSum);     RPC_METHOD(int summ(int a, int b))     {      lastSum = a + b;      return lastSum;     } }; On machine A I had its instance. On machines B and C I had created its instances and connected...

  • For this project, each part will be in its oun matlab script. You will be uploading a total 3 m f...

    For this project, each part will be in its oun matlab script. You will be uploading a total 3 m files. Be sure to make your variable names descriptive, and add comments regularly to describe what your code is doing and hou your code aligns with the assignment 1 Iterative Methods: Conjugate Gradient In most software applications, row reduction is rarely used to solve a linear system Ar-b instead, an iterative algorithm like the one presented below is used. 1.1...

  • A code in matlab. (maybe Jammer can answer)? Consider the following income tax brackets. Income ($)...

    A code in matlab. (maybe Jammer can answer)? Consider the following income tax brackets. Income ($) 0 - 10,000 10,000 - 25,000 Tax 0% 5% on amount exceeding 10,000 $750 + 8% on amount exceeding 25,000 $2,750 + 10% on amount exceeding 50,000 $7,750 + 15% on amount exceeding 100,000 $67,750 + 25% on amount exceeding 500,000 25,000 - 50.000 50,000-100,000 100,000-500,000 > 500,000 250 Thus, if the income is $70,000, then the fourth bracket will apply and the tax...

  • Help with SIMULINK of Matlab: I want to put the transfer function, I have already located...

    Help with SIMULINK of Matlab: I want to put the transfer function, I have already located function # 1, but how do I put function 2, so that it comes out as well as the original function, what should I put in the numerator and denominator? .. Block Parameters: Transfer Fcn5 Х Transfer Fon Function1: K*wn^2 S2+2*zhita*wns The numerator coefficient can be a vector or matrix expression. The denominator coefficient must be a vector. The output width equals the number...

  • I am creating a recursive function in c++ and have the following code so far. However,...

    I am creating a recursive function in c++ and have the following code so far. However, can you help me fix it so that it doesn't crash when negative numbers are entered. If negative numbers are entered i want to let the user know negative numbers are not accepted and to try again #include <iostream> using namespace std; int multiplication(int x, int y) { int sum = y; //if value of x is 1, then result of x*y will be...

  • In this exercise, you will work with a QR factorization of an mxn matrix. We will proceed in the ...

    In this exercise, you will work with a QR factorization of an mxn matrix. We will proceed in the way that is chosen by MATLAB, which is different from the textbook presentation. An mxn matrix A can be presented as a product of a unitary (or orthogonal) mxm matrix Q and an upper-triangular m × n matrix R, that is, A = Q * R . Theory: a square mxm matrix Q is called unitary (or orthogona) if -,or equivalently,...

  • In matlab, I keep getting the same issue for this problem can someone help? "myrowproduct.m" >> Filename...

    In matlab, I keep getting the same issue for this problem can someone help? "myrowproduct.m" >> Filename myrowproduct (A,x) Undefined function or variable 'Filename' Did you mean: mfilename : myrowproduct (A, x) Undefined function or variable 'myrowproduct' function y = myrowproduct(A,x); function y my rowp roduct (A, x); Error: Function definition not supported in this context. Create functions in code file. (, 2,,)T 4. The product y Ax of an m x n matrix A times a vector x= can...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT