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

In summary, you can use Matlab to apply a formula to data, such as z = x^2 + y^6, to obtain values of z. This can be done using the elementwise operation .^ and is useful for handling large amounts of data. You can also transfer and import data from Excel into Matlab using Dynamic Data Exchange (DDE) or by saving the Excel worksheet as a text file and using the load function in Matlab.
  • #1
Benny
584
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
  • #2
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
 
  • #3
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?
 
  • #4
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.
 
  • #5
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.
 

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

1. How do I efficiently evaluate z values in Matlab using the formula with 15+ data points?

To efficiently evaluate z values in Matlab, you can use the built-in function normcdf which calculates the cumulative distribution function for a normal distribution. This function takes in a vector of data points and returns a vector of z values. Alternatively, you can also use the normpdf function to directly calculate the probability density function for each data point and then convert it to z values using the formula z = (x - mu)/sigma, where x is the data point, mu is the mean, and sigma is the standard deviation.

2. Can I use the formula to evaluate z values for any type of data?

Yes, the formula for converting data points to z values can be used for any type of data as long as it follows a normal distribution. However, if your data does not follow a normal distribution, this formula may not be appropriate.

3. What if I have less than 15 data points, can I still use this formula?

Yes, this formula can be used for any number of data points. However, it is recommended to have at least 15 data points to get a more accurate representation of the normal distribution.

4. How do I interpret the z values that are calculated?

Z values represent the number of standard deviations a data point is from the mean of a normal distribution. A positive z value indicates that the data point is above the mean, while a negative z value indicates that the data point is below the mean. The larger the absolute value of the z value, the further the data point is from the mean.

5. Are there any other methods for evaluating z values in Matlab?

Yes, in addition to the formula and built-in functions mentioned, there are also other statistical functions in Matlab such as zscore and stdnormalcdf that can be used to evaluate z values. It is recommended to explore and compare these different methods to find the most efficient and accurate one for your specific data set.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Replies
3
Views
780
  • Set Theory, Logic, Probability, Statistics
Replies
5
Views
532
  • Special and General Relativity
4
Replies
123
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
  • Differential Geometry
Replies
16
Views
2K
  • Programming and Computer Science
Replies
25
Views
2K
Replies
1
Views
2K
Replies
7
Views
3K
Back
Top