In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the use of the summation function sum in Matlab, which is very detailed and has a certain reference value. Friends who are interested must finish it!
The use of Matlab summation function sum: 1, use [S = sum (A)] to sum; 2, use [S = sum (Ajindim)] to sum according to the specified dimension; 3, use [S = sum (_ _, outtype)] to specify the data type of the output result.
How to use the summation function sum of Matlab:
1. S = sum (A), summation
If x is a vector, the sum of the elements of the vector is calculated, such as:
> > x = randi (10 Personl 10) x = 7 1 9 10 7 8 4 7 2 > > sum (x) ans = 63
If the array of x is the sum of the columns of the computed array, such as:
> > x = pascal (4pm 2) x =-1-1-1-1321 10-3-1001000 > > sum (x) ans = 0 000-1
2. S = sum (A _ cadine dim), summing according to the specified dimension
Dim = 1, indicating the sum of columns
Dim = 2, indicating the sum of rows
Dim = 3, indicating the summation of the page
., and so on.
For example:
> a = toeplitz (1:5) a = 12 3 4 5 2 12 3 4 3 2 12 3 4 3 2 12 5 4 3 21 > > sum (a prime1) ans = 15 12 11 12 15 > > sum (a prime2) ans = 15 12 11 12 15
3. S = sum (_ _, outtype) specifies the data type of the output result
Optional string parameters are 'double','default' and' native'
Generally speaking, the default is' default'
Sometimes we can use this parameter when we sum integers and want the result to be of type double.
For example:
> > a = single (1:4) a = 1234 > > class (sum (a mahjong') ans = double > > class (sum (a)) ans = single
Although the data types of Matlab are comprehensive, the data type conversion is not exactly the same as that of other languages, so you need to be careful when using it.
4. Whether S = sum (_ _, nanflag) ignores nan value
Sometimes when summing, there is the influence of nan value in the data, which leads to NaN in the calculation result. The general processing method is to use the isnan function to exclude the nanvalue. With this option, it is simple.
Such as:
> > a = rand (1Magol 6); a (randperm (6Magne2)) = NaNa = 0.7060 0.0318 NaN 0.0462 0.0971 NaN > > sum (a) ans = NaN > > sum (a) ans = 0.8812 is all the contents of this article entitled "examples of the use of sum in Matlab". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.