Efficiently Evaluate z Values in Matlab using Formula - 15+ Data Points

  • Context: MATLAB 
  • Thread starter Thread starter Benny
  • Start date Start date
  • Tags Tags
    Formula Matlab
Click For Summary

Discussion Overview

The discussion revolves around evaluating z values in Matlab using a specified formula based on input data points. Participants explore methods for efficiently handling larger datasets, particularly when transitioning data from Excel to Matlab.

Discussion Character

  • Technical explanation
  • Exploratory
  • Homework-related

Main Points Raised

  • One participant inquires about using Matlab to evaluate z values from given data points, suggesting a formula z = x^2 + y^6.
  • Another participant clarifies that the operation ^ is not defined for vectors in Matlab, recommending the use of elementwise operations with .^.
  • A participant proposes a method to calculate z using vectors, expressing concern about the impracticality of manually entering large datasets into Matlab.
  • Suggestions are made for importing data from Excel into Matlab, including using Dynamic Data Exchange (DDE) and saving Excel data as a text file for loading into Matlab.
  • A later reply confirms the validity of the proposed Matlab command for calculating z values and shares a personal experience of successfully testing the method with random numbers.

Areas of Agreement / Disagreement

Participants generally agree on the methods for using Matlab to evaluate z values and the feasibility of importing data from Excel, though there is no explicit consensus on the best approach for larger datasets.

Contextual Notes

Some limitations include the need for clarification on the definitions of operations in Matlab and the specifics of data formatting when importing from Excel.

Benny
Messages
577
Reaction score
0
If I have some data for example (x_1,y_2) = (1,1), (x_2,y_2) = (2,2) and (x_3,y_3) = (3,3) [they aren't coordinates, it's just a convenient way to show the information] and I want to evaluate the values of z (z_1, z_2 and z_3) where for example z = x^2 + y^6, can I enter the formula for z into Matlab to do this for me?

For just 3 bits of data I can do it by hand but if I have 15+ then it gets tiresome so I'd like to know if I can use Matlab to apply a formula to data (like the example above) to get out the required values. Any help would be good, thanks.
 
Physics news on Phys.org
I suppose that by x and y you mean two column vectors. The operation ^ is not defined for vectors, only for scalars and square matrixes, but in Matlab you can use the elementwise operation .^:
z = x.^2 + y.^6
 
So for example could I do the following to obtain values of z?

x = [1 2 3 4];
y = [1 2 3 4];
z = x.^2+y.^4


That sort of method is ok for a few values. But if I have 50 or so pieces of data then it's impractical to enter column vectors with 50 elements into Matlab. Is it possible to transfer/import, the data entered into the worksheets of Excel, to Matlab and use commands in Matlab to apply some function (for example z = x^2+y^2) on the data (x,y) to obtain values of z?
 
Benny said:
So for example could I do the following to obtain values of z?

x = [1 2 3 4];
y = [1 2 3 4];
z = x.^2+y.^4
Yes, this is a valid command.
That sort of method is ok for a few values. But if I have 50 or so pieces of data then it's impractical to enter column vectors with 50 elements into Matlab. Is it possible to transfer/import, the data entered into the worksheets of Excel, to Matlab and use commands in Matlab to apply some function (for example z = x^2+y^2) on the data (x,y) to obtain values of z?
For use of Matlab with Excel and other Windows applications, read the Matlab Help about Dynamic Data Exchange (DDE).
Alternatively, you can save the columns of your Excel worksheet as a text file and use the load Matlab function to import them as a matrix.
For instance, suppose you have a worksheet with 2 columns and you save it as test.txt. In Matlab you can use the command load test.txt in the appropriate directory. You have in your work directory a matrix named test.
Now you can use the command z = test(:,1).^2 + test(:,2).^4 to get your result.
 
Ok thanks. I ended up just trying testing some things by putting in some random numbers into a column of excel, pasting it into a 'half-complete' vector in Matlab, closed out the vector with the square bracket na dthen applied some element wise operations. It worked so that was good.
 

Similar threads

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