MATLAB Create Table for Matlab Newtonian Cooling Solution

  • Thread starter Thread starter MechanicalMan
  • Start date Start date
  • Tags Tags
    Matlab Table
AI Thread Summary
The discussion revolves around creating a table of results in MATLAB for a graduate-level assignment on Newtonian cooling. The user seeks guidance on how to format and display data in a tabular format similar to Excel. A solution is provided using a for loop and the fprintf function to print temperature and time values from array variables. The example illustrates how to format output for integer data, with a note that different conversion specifiers are needed for floating-point data.Additionally, another user inquires about importing Excel data into MATLAB, asking for methods to create a function that addresses specific rows and columns. Two primary methods are suggested: using the data importer GUI or the xlsread function. The discussion emphasizes the importance of MATLAB's tutorials and documentation for users unfamiliar with the software.
MechanicalMan
Messages
25
Reaction score
0
Hi all,

I'm writing a program for a graduate level course that I'm taking wherein I'm solving the Newtonian cooling solution for a long metal rod with specified properties.

I have no problem setting up the code and generating a plot, but I am running into problems creating a table of the results. The requirement for the assignment is to present the data in both tabular and graphical format.

If I'm dealing with, say, T(t) and t as dependent and independent variables, respectively, how do I go about creating a table, much like I could get from excel?

For example, I'm hoping for something such as:

T(t) t
50 1
40 2
30 3
etc..

Thanks in advance for your help.
 
Physics news on Phys.org
Your variables for T and t are array variables. Displaying them is a matter of looping through the pairs of values with a for loop, and displaying them with the fprintf function. Assuming your arrays have 50 elements, your code would look something like this.

Code:
% Print a header to standard output device
fprintf(1, "Temperature\t time\n")
% Loop through temperature and time arrays
for i = 1:50
   fprintf(1, "%d\t%d\n", T(i), t(i))
end

The example data you showed consisted of integers, and I used conversion specifiers in the second fprintf call to accommodate integers. If your data is floating point, you will need different conversion specifiers. Here's a link to the fprintf documentation: http://www.mathworks.com/access/helpdesk/help/techdoc/ref/fprintf.html.
 
Hi,

I am trying to write MATLAB codes for an excel table (Bsically create a function). In the first column (header), there are some characteristics and in the first row, there are some experimental results for the characteristics. How can I do that to address each datium in a specific row and column?

Thanks
 
Welcome to PhysicsForums!

In the future, if you have a new topic, please post a new topic, rather than posting in someone else's post, especially one that's over a year old.

As for your specific question, are you asking how to import .xls (or .xlsx) files into MATLAB, or how to work with them once imported? If you're new to MATLAB, I highly suggest their Getting Started series, or their Tutorial series (e-mail registration is required for the Tutorial series, but not the Getting Started).

Tutorials:
http://www.mathworks.com/academia/student_center/tutorials/launchpad.html

Getting Started:
http://www.mathworks.com/help/techdoc/learn_matlab/bqr_2pl.html
 
Last edited by a moderator:
Thanks for your prompt response and sorry about replying here. I was wondering how I can import the excel file (the table) into the MATLAB?? Basically, I want to create a function to address each column and row.

Thanks again
 
Well, there are two ways of importing Excel data, without having to manually do things line by line or column by column. The first is via the data importer, which has a nice graphical user interface--GUI--to guide you through the process (type in uiimport at the MATLAB prompt):
http://www.mathworks.com/help/techdoc/ref/uiimport.html

The second is to use xlsread:
http://www.mathworks.com/help/techdoc/ref/f16-5702.html#f16-14631

You can find detailed information (including examples) on all MATLAB functions at the site I linked to. You can also find some basic information within the program by typing in help <NAME OF FUNCTION>. For instance, typing in the following will bring up a little blurb on the uiimport function:
>> help uiimport

Once you have it in MATLAB, you can address individual elements using the techniques here:
http://en.wikibooks.org/wiki/MATLAB_Programming/Introduction_to_array_operations

Still, the MATLAB tutorials / getting started guide I linked to in my previous post will get you up to speed fairly quickly if you're new to MATLAB.
 
Last edited by a moderator:
Back
Top