Tabulate data from the mathlab program

In summary, to tabulate data from the MathLab program, you can use the table function. You can also customize the appearance of the table using the uitable function and export the data to a spreadsheet using the xlswrite function. Additionally, it is possible to perform calculations on the tabulated data using various mathematical functions such as sum, mean, and median. Other tools and functions available for tabulating data in the MathLab program include histogram, boxplot, and scatter.
  • #1
iwan89
27
0
I need to tabulate the data for u(x,t) vs x. Someone help me please :(
this is the program.

L = 1.;
T = 1.;
maxk = 2500;
dt = T/maxk;
n=50;
dx = L/n;
cond = 1/4;
b = 2.*cond*dt/(dx*dx);
for i= 1:n+1
x(i) = (i-1)*dx;
u(i,1) = sin(pi*x(i));
end
for k=1:maxk+1
u(1,k) = 0.;
u(n+1,k)=0.;
time(k) = (k-1)*dt;
end
for k=1:maxk
for i=2:n;
u(i,k+1)=u(i,k)+0.5*b*(u(i-1,k)+u(i+1,k)-2.*u(i,k));
end
end
figure (1)
plot (x,u(:,1),'-',x,u(:,100),'-',x,u(:,300),'-',x,u(:,600),'-')
title ('Temperature within the explicit method')
xlabel ('X')
ylabel ('Y')
figure (2)
mesh (x,time,u')
title ('Temperature within the explicit method')
xlabel ('X')
ylabel ('Temperature')
 
Physics news on Phys.org
  • #2
iwan89 said:
I need to tabulate the data for u(x,t) vs x. Someone help me please :(
What do you mean? Do you need to print the data in a table? If so, how many columns? What should the table look like?

BTW, this is not the section for HW problems. I am moving this post back to where your other one is.
iwan89 said:
this is the program.

L = 1.;
T = 1.;
maxk = 2500;
dt = T/maxk;
n=50;
dx = L/n;
cond = 1/4;
b = 2.*cond*dt/(dx*dx);
for i= 1:n+1
x(i) = (i-1)*dx;
u(i,1) = sin(pi*x(i));
end
for k=1:maxk+1
u(1,k) = 0.;
u(n+1,k)=0.;
time(k) = (k-1)*dt;
end
for k=1:maxk
for i=2:n;
u(i,k+1)=u(i,k)+0.5*b*(u(i-1,k)+u(i+1,k)-2.*u(i,k));
end
end
figure (1)
plot (x,u(:,1),'-',x,u(:,100),'-',x,u(:,300),'-',x,u(:,600),'-')
title ('Temperature within the explicit method')
xlabel ('X')
ylabel ('Y')
figure (2)
mesh (x,time,u')
title ('Temperature within the explicit method')
xlabel ('X')
ylabel ('Temperature')
 
  • #3
yes i want to print the data and put it inside the table. two colomn which represent the graph
 
  • #5
Im in total lost :( can you help me to modify my program so that it can create a table? :(
 
  • #6
Something like this. I don't know if this is exactly what you need, but it's probably close.
Code:
formatSpec = "%4.2f \t %4.2f \n";
for k=1:maxk
  for i=2:n;
    u(i,k+1)=u(i,k)+0.5*b*(u(i-1,k)+u(i+1,k)-2.*u(i,k));
    fprintf(formatSpec, x(i), u(i, k + 1))
  end
end
 
  • #7
what is %4.2f \t %4.2f \n meant?
 
  • #8
%4.2f is a format specifier - print a number in a field of width 4, with 2 places to the right of the decimal point. If you have numbers that take up more space, change the 4 to something bigger. If you want more places to the right of the decimal, change the 2 to something bigger.

\t is a tab character
\n is a newline character.
 

Related to Tabulate data from the mathlab program

1. How do I tabulate data from the MathLab program?

To tabulate data from the MathLab program, you can use the table function. This function takes in a vector or matrix of data and creates a table with the values displayed in columns and rows.

2. Can I customize the appearance of the table generated by the MathLab program?

Yes, you can customize the appearance of the table generated by the MathLab program by using the uitable function. This function allows you to specify the column names, row names, and cell values of the table.

3. How can I export the tabulated data from the MathLab program to a spreadsheet?

To export the tabulated data from the MathLab program to a spreadsheet, you can use the xlswrite function. This function allows you to specify the file name and path, as well as the data to be exported.

4. Is it possible to perform calculations on the tabulated data in the MathLab program?

Yes, it is possible to perform calculations on the tabulated data in the MathLab program. You can use the sum, mean, median, and other mathematical functions to perform calculations on the data.

5. Are there any other tools or functions available in the MathLab program for tabulating data?

Yes, there are other tools and functions available in the MathLab program for tabulating data. These include the histogram function for creating a histogram of the data, the boxplot function for creating a box plot of the data, and the scatter function for creating a scatter plot of the data.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
980
  • Engineering and Comp Sci Homework Help
Replies
2
Views
856
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
116
  • Engineering and Comp Sci Homework Help
Replies
7
Views
913
  • Calculus and Beyond Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
3K
Back
Top