how to change disp for fprintf
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
%Algoritmo sist_ecs_lineales
n=input("Proporciona el número de incógnitas del sistema");
Au=input("Ingresa la matriz aumentada del sistema");
disp(Au)
[num_filas,num_columnas]=size(Au); %n Es el número de incognitas del sistema
disp("Primer paso de la Eliminación de Gauss (ESTRATEGIA DE PIVETEO NATURAL)")
disp("a)Elección del pivote")
pivote=Au(1,1)
disp("b) Poner ceros debajo de la columna de donde se eligio el pivote")
%Calcula los multiplicadores (escalares)
lambda1=Au(2,1)/pivote;
lambda2=Au(3,1)/pivote;
Au(2,:)=-lambda1*Au(1,:)+Au(2,:)
Au(3,:)=lambda2*Au(1,:)+Au(3,:)
disp("Primer paso de la Eliminación de Gauss (ESTRATEGIA DE PIVETEO NATURAL)")
disp("a)Elección del pivote")
pivote=Au(1,1)
disp("b) Poner ceros debajo de la columna de donde se eligio el pivote")
%Calcula los multiplicadores (escalares)
lambda1=Au(3,2)/pivote;
Au(3,:)=-lambda1*Au(2,:)+Au(3,:)
disp("SUSTITUCIÓN HACIA ATRAS")
%Fin algoritmo
1 comentario
Adam Danz
el 28 de Abr. de 2021
Editada: Adam Danz
el 28 de Abr. de 2021
We need to know what the expected inputs are to be displayed. Rather than needing to run your code, how about you provide some more specific examples of what is being displayed and how you would like it to appear using fprintf.
Respuestas (1)
Adam Danz
el 28 de Abr. de 2021
Editada: Adam Danz
el 28 de Abr. de 2021
Starting in Matlab r2021a, you can use formattedDisplayText() to capture anything that is displayed by disp().
If you want to use fprintf instead, there are several examples in the documentation but when it comes to displaying multidimensional arrays such as matrices, it gets tricky. See the example provided by Jan.
You could also use string or num2str for numeric conversion to strings or character arrays.
Examples
% Example 1
a = randi(9,3,3)
formattedDisplayText(a)
string(a)
num2str(a)
% Example 2
b = {'a', 7; 'b', 12}
string(b)
formattedDisplayText(b)
0 comentarios
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!