How to replace values in a table with the outputs of another code?

4 Ansichten (letzte 30 Tage)
I am attempting to create a table that will display the results gotten from running through another MATLAB code however I just cannot seem to replace the values in the table with the new values.
I have the Table labeled so that I can output it but I don't understand why I can't replace the Table values (that I have currently stored as 0's) with the outputs. I got and error originally saying that the right hand side needed to be a table or an array (Originally i just had the "minPModel" and such but since replaced them with the new table "MinMaxTab" and it still won't accept it). I don't understand how to get it to work.
Attached is the MinMax file
Table1 = table([0.50; 0.75; 1; 1.25; 1.5; 1.75; 2],...
[0; 0; 0; 0; 0; 0; 0],...
[0; 0; 0; 0; 0; 0; 0],...
[0; 0; 0; 0; 0; 0; 0],...
[0; 0; 0; 0; 0; 0; 0],...
'VariableNames',{'R (mmHg*s/ml)' 'Pressure Maximum (mmHg)' 'Pressure Minimum (mmHg)' 'Presure Mean (mmHg)' 'Pulse Pressure (max-min) (mmHg)'});
for R = 0.5:.25:2
k = 2;
fprintf("R = %d", R);
run MinMax.m;
MinMaxTab = [minPModel; maxPModel; meanPModel];
Table1(2,k) = MinMaxTab(1,1);
Table1(3,k) = MinMaxTab(1,2);
Table1(4,k) = MinMaxTab(1,3);
Table1(5,k) = Table1(3,k)-Table1(2,k);
k=k+1;
end
Table1

Akzeptierte Antwort

Stephen23
Stephen23 am 12 Sep. 2024
Bearbeitet: Stephen23 am 12 Sep. 2024
Use curly brace indexing to access the content of the table:
Generally it is easier and clearer to loop over indices, not over data values.
It also seems that you have accidentally transposed the row and column indices. I fixed that for you.
Y = 0.5:0.25:2;
Z = zeros(size(Y));
Table1 = table(Y(:),Z(:),Z(:),Z(:),Z(:), 'VariableNames',{'R (mmHg*s/ml)' 'Pressure Maximum (mmHg)' 'Pressure Minimum (mmHg)' 'Presure Mean (mmHg)' 'Pulse Pressure (max-min) (mmHg)'});
for k = 1:height(Table1)
MinMaxTab = randi(9,1,3);
Table1{k,2} = MinMaxTab(1,1);
Table1{k,3} = MinMaxTab(1,2);
Table1{k,4} = MinMaxTab(1,3);
Table1{k,5} = Table1{k,3}-Table1{k,2};
end % ^ ^ curly braces
Table1
Table1 = 7x5 table
R (mmHg*s/ml) Pressure Maximum (mmHg) Pressure Minimum (mmHg) Presure Mean (mmHg) Pulse Pressure (max-min) (mmHg) _____________ _______________________ _______________________ ___________________ _______________________________ 0.5 1 2 2 1 0.75 9 9 8 0 1 7 8 7 1 1.25 1 2 5 1 1.5 6 7 2 1 1.75 2 9 4 7 2 2 6 4 4

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by