why I can't save everything into a Matlab Script file?

2 次查看(过去 30 天)
%First set of polynomials
p1 = [15 9 -22];
p2 = [8 -17 -12];
P = p1 + p2;
disp('The sum of the polynomial is')
The sum of the polynomial is
disp(P)
23 -8 -34
%Second Set of Polynomials
x1 = [7 0 -3];
x2 = [-15 -13 18];
X = x1 + x2;
disp('The sum of the polynomial is')
The sum of the polynomial is
disp(X)
-8 -13 15
%Expanding first expression
syms x y
B = (3*x + 4*y)^3;
A = expand (B);
disp('Expanded form of (3x + 4y)^3:');
Expanded form of (3x + 4y)^3:
disp(A);
%Expanding second expression
syms m n
B = (5*m^2 + 4*n^2)^5;
A = expand (B);
disp('Expanded form of (5*m^2 + 4*n^2)^5');
Expanded form of (5*m^2 + 4*n^2)^5
disp(A);
%factoring first polynomial
syms a;
A = (a^3 + 5*a^2 - 2*a-24);
B = factor (A);
disp('Factor form of (a^3 + 5*a^2 - 2*a-24) ');
Factor form of (a^3 + 5*a^2 - 2*a-24)
disp(B);
%factoring second polynomial
syms x
A = 4*x^3 + 3*x^2 - 25*x + 6;
B = factor(A);
disp('Factored form of 4x^3 + 3x^2 - 25x + 6:');
Factored form of 4x^3 + 3x^2 - 25x + 6:
disp(B);
%factoring third polynomial
syms x
A = x^4 - 10*x^2 + 9;
B = factor (A);
disp('Factored form of x^4 - 10*x^2 + 9:');
Factored form of x^4 - 10*x^2 + 9:
disp(B);
CAN'T SAVE AS MATLAB SCRIPT FILE

回答(1 个)

Pavan Sahith
Pavan Sahith 2024-6-24
Hello Aj,
I noticed that you're encountering the warning: "The variables that could not be saved into MATLAB Script are saved into MAT file" while trying to save your workspace variables to a MATLAB script file.
This warning appears because some of the variables in your workspace cannot be represented as MATLAB code within a script file. To understand this better, you need to know differences between a MAT file and a MATLAB script file.
Script files are meant to be executed. When you load a script file, MATLAB runs the commands in the file to recreate the variables.
  • Certain types of variables such as MATLAB objects, function handles, and anonymous functions cannot be saved into a script file and are instead stored in a MAT-file.
  • MATLAB provides the 'matlab.io.saveVariablesToScript' function to save workspace variables to a script file. However, it has limitations on what can be saved to a script.
MAT files are optimized for storing and retrieving data. They handle large datasets and complex structures efficiently, which a text-based script cannot. Loading a MAT file is typically faster and more reliable than executing a script to recreate the same variables.
If you use the MATLAB Editor's "Save Workspace As" feature and select "MATLAB Script," MATLAB will attempt to generate a script file that recreates these variables. However, if some variables cannot be converted to code, MATLAB will:
  1. Generate a Script File: For variables that can be represented as MATLAB code, MATLAB will create a script file (e.g., workspace_script.m).
  2. Save to a MAT File: For variables that cannot be converted to code, MATLAB will save them into a MAT file (e.g., workspace_script.mat) and issue a warning.
you can refer to the following MathWorks Documentation to understand more
Hope the above information helps you

类别

Help CenterFile Exchange 中查找有关 Number Theory 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by