Create Table for Matlab Newtonian Cooling Solution

  • Context: MATLAB 
  • Thread starter Thread starter MechanicalMan
  • Start date Start date
  • Tags Tags
    Matlab Table
Click For Summary

Discussion Overview

The discussion revolves around creating a table for the results of a Newtonian cooling solution in MATLAB, specifically focusing on how to format and display data in both tabular and graphical formats. Participants are exploring methods to handle data arrays and import Excel files into MATLAB.

Discussion Character

  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant describes their issue with generating a table of results for a MATLAB program related to Newtonian cooling, seeking advice on how to format the output.
  • Another participant suggests using a for loop and the fprintf function to display temperature and time arrays, providing a code snippet as an example.
  • A different participant inquires about creating a MATLAB function to generate an Excel table, asking how to address specific data points in rows and columns.
  • One participant advises on the importance of starting new topics for new questions and offers guidance on importing Excel files into MATLAB.
  • Another participant explains two methods for importing Excel data into MATLAB: using the data importer GUI and the xlsread function, providing links to documentation for further reference.

Areas of Agreement / Disagreement

Participants generally agree on the methods for displaying and importing data in MATLAB, but there are multiple approaches discussed without a consensus on the best method for all scenarios.

Contextual Notes

Some participants mention specific functions and methods without detailing the assumptions or limitations of those methods, such as the need for different conversion specifiers for floating-point data in fprintf.

Who May Find This Useful

Readers interested in MATLAB programming, particularly those working on data presentation and analysis in scientific contexts, may find this discussion relevant.

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:

Similar threads

  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
1
Views
18K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
9K