Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to define a matrix of variables in matlab as function ?

Status
Not open for further replies.
I'm not sure exactly what you are asking for. My interpretation is that you want to write a function that returns a matrix. I have some doubt because I think that maybe you are looking to define a matrix with some variables in it, and you want the matrix to be updated whenever you update the variables.

For either of those, perhaps you can do something like this:

In junk.m
Code:
function B = junk (a,b,c,d)
   B = [a, b ; c, d];
endfunction

You can call the function with the input variables wherever you would have been using the matrix variable that you were using.
 

thank but i mean tha i have
my function: for exemple matrix (1x7) zise
one var x for exemple cost in (1x7) zise and i want choose this matrixe from data
for exemple i have 7 cost and i want chose 5 best cost
how i define this matrix and how choose the best 5 cost if i give sum of my cost for exemple equal 20 dollars oki
 
Last edited:

You can define a variable-size matrix by using a constructor with nonconstant dimensions. For example:

function y = var_by_assign(u) %#codegen
if (u > 0)
y = ones(3,u);
else
y = zeros(3,1);
end
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top