Clear Filters
Clear Filters

I am trying to plot the fuctions "phi_i_store1" which is stored as 1x1 sym. Is there a way to plot it without using fplot as I want to be able to see the variables of the plot

1 view (last 30 days)
phi_i_store1 = 0;
for i = 1 : 10
phi_i = ((y/l)^(i+1)*(2+i-i*(y/l)))/(i*(i+1)*(i+2));
phi_i_store1 = phi_i_store1 + phi_i*V(i,1); % V is a matrix with stored variables
end
y = 0 : 1 : 44;
x = phi_i_store1;
plot(y,x) %avoiding fplot so that I can see the variables plotted in a matrix

Answers (1)

Abhishek Chakram
Abhishek Chakram on 25 Apr 2024
Hi Joel Hing,
To plot “phi_i_store1” without using “fplot”, you need to evaluate the expression for a range of “y” values, then plot the evaluated results. Since “phi_i_store1” is initially defined symbolically and depends on “y” and elements from the matrix “V”, you will need to substitute the values of “y” into “phi_i_store1” before plotting. However, the loop you have shown for calculating “phi_i_store1” seems to be missing the symbolic declaration for “y” and “l”, and it directly uses “y” in arithmetic operations before its range is defined. Here is the corrected version of the code:
syms y
l = 10; % Example value, adjust as necessary
V = rand(10, 1); % Example matrix, replace with your actual V matrix
phi_i_store1 = 0;
for i = 1 : 10
phi_i = ((y/l)^(i+1)*(2+i-i*(y/l)))/(i*(i+1)*(i+2));
phi_i_store1 = phi_i_store1 + phi_i*V(i,1); % Assuming V is defined
end
yRange = 0 : 1 : 44; % Define the range for y
xValues = double(subs(phi_i_store1, y, yRange)); % Evaluate phi_i_store1 for each y
plot(yRange, xValues) % Plot the results
xlabel('y')
ylabel('phi_i_store1')
title('Plot of phi_i_store1 vs. y')
You can refer to the following documentation to know more about functions used:
Best Regards,
Abhishek Chakram

Categories

Find more on Line Plots 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!