Creating matrix and then using it in another code.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Aniket Dutta
am 24 Aug. 2022
Kommentiert: Aniket Dutta
am 24 Aug. 2022
I want to create a matrix in progression. I have 10000 random values of X in a spreadsheet. i want to impost it and then create a diagonal matrix in the form of
X 0 0 0
0 X 0 0
0 0 0 X
0 0 0 X
But for 10000 times for all 10000 different values of X in one run.
Basically I want to do Monte Carlo but with the elements of the matrix keeping the diagonal values same and getting 10000 different matrices and then run another code with of those 10000 values inone run and plot how it acts in a graph.
0 Kommentare
Akzeptierte Antwort
Abderrahim. B
am 24 Aug. 2022
Bearbeitet: Abderrahim. B
am 24 Aug. 2022
Hi!
Not sure if I understood your question correctly, but here is a potential answer:
% Creating dummy data. in your case use readmatrix() to import data
A = randi(10, 1000, 1) ;
B = diag(A);
Edit:
for ii = 1:length(A)
B = diag(A(ii)*ones(4,1))
end
HTH
8 Kommentare
Abderrahim. B
am 24 Aug. 2022
Did not get very well what you wanted to say! Below assuming that you want to create 6x6 matrices from the A,and store them in a struct :
A = randi(10, 1000, 1) ;
S_four = struct ;
S_six = struct ;
for ii = 1:length(A)
S_four(ii).B = diag(A(ii)*ones(4,1)) ;
S_six(ii).B = diag(A(ii)*ones(6,1)) ;
end
% want to access data in a field, use dot notation
B_six1 = S_six(1).B
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!