How to pass a Matrix of cell array as a input argument to a function
Show older comments
Hey all,
I already asked this question in different way. But now I came up with my code instead of just explanation.
This is my user input matrix file:
function [Lambda, A, B, D] = Matrix_surendra13
n =7 ;
% Conductivity Matrix size preallocation
Lambda = ones(1,n);
% Area Matrix size preallocation
A = ones(n,n);
% Diameter matrix Size definition
D = ones (1,n);
%Width matrix Size definition
B = ones(1,n);
Lambda = [205 50.2 0.025893 79.5 0.180 7720 0.025893];
D = [ 55 55 0 55 0 55 0];
%Here you can see in cell array A , A{1,2} and A{2,1} are same. So I need to pass whole matrix as input arguments to the function in the slover.
A = { 0 [ 2375.80 4749.50 1457.25] 0 0 0 0 2375.80 ;
[ 2375.80 4749.50 1457.25] 0 2375.80 4749.50 0 0 1835.80;
0 2375.80 0 0 0 0 0;
0 4749.50 0 0 2375.80 4749.50 1835.80;
0 0 0 2375.80 0 0 0;
0 0 0 4749.50 0 0 2375.80 ;
2375.80 1835.80 0 1835.80 0 2375.80 0};
B = [ 25 30 0 20 0 35 0];
end
This is my solver:
function SampleModel13_Stat(Measuring_Data)
[Lambda, A, B, D] = Matrix_surendra13;
n = size(A,1);
m = size(A,2);
LA = zeros(n,m);
for i=1:n
for j=1:n
% for ii = 1: after colon, size of the matrix inside cell array
% for jj = 1: after colon size, of the matrix inside cell array, but I am not sure whether it is %correct or not to pass the matrix elements one by one at the same time.
%How to find the size of the matrix inside the cell array.
LA(i,j) = Leitwert_L_2_3(Lambda(i),Lambda(j), A{i,j}A(ii,jj), A{i,j}A(ii,jj), A{i,j}A(ii,jj), B(i),B(j));
%end
%end
LA(i,j)= Leitwert_L(Lambda(i), Lambda(j), A(i,j), B(i), B(j)); % this is fine for the rest of the things
end
end
disp(LA);
end
I have two questions.
First one is, How to find the size of the matrix inside the cell array. may be using length(A{1,2}, I will get only the length of row elements. but not the size of the matrix or using numel.
Second one is How to pass all the arguments of the matrix of the cell array A{1,2}, to a function in the slover.
Like below
A{1,2}A(1,1), A{1,2}A(1,2), A{1,2}A(1,3) %first element of the matrix is for A{1,2}A(1,1) and same for rest of the things.
A{2,1}A(1,1), A{2,1}A(1,2), A{2,1}A(1,3)
I don't know whether it is possible using for loop or not, but I am trying it still.
I hope that explantion is enough, if you still need an explantion, I am ready to give.
Any suggestions and answers would be much appreciated
Thanks in Advance
2 Comments
Bob Thompson
on 24 Jun 2019
I'm not sure what you mean with this designation: A{1,2}A(1,1). Are you just trying to access the first element of the A{1,2}? If so, that would be written out this way, A{1,2}(1,1). (You don't need the second 'A.'
'Second one is How to pass all the arguments of the matrix of the cell array A{1,2}, to a function in the slover.'
When you say, 'pass the arguments,' I'm assuming that you mean the elements of a matrix. Do you want them passed individually, or the entire cell at the same time? The for loops that you have set up will accomplish this, though they may take some time. You can try using cellfun, but at its heart it is still a for loop.
surendra kumar Aralapura mariyappa
on 24 Jun 2019
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements 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!