Assign a value to a matrix element defined as a variable
Show older comments
Hi all,
Is it possible to assign values (variables) to elements in a matrix that is defined as a function handle?
For example:
prop1 = zeros(2);
prop1(:,1) = 1;
prop1(:,2) = 2;
prop1
prop2 = @(x) [0 0;
0 0]
prop2(:,2) = @(x) x(2)
I would like to assign variables to prop2 as I did to prop1.
2 Comments
Geovane Gomes
on 17 Jun 2023
Edited: Geovane Gomes
on 17 Jun 2023
Steven Lord
on 17 Jun 2023
Use repmat or repelem.
Accepted Answer
More Answers (1)
Voss
on 17 Jun 2023
prop = @(x)[x([repmat([1 3],11,1); repmat([2 4],12,1)]) zeros(23,2)];
1 Comment
Geovane Gomes
on 17 Jun 2023
Categories
Find more on Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!