Excel SUM IF in MATLAB?

6 次查看(过去 30 天)
Jared
Jared 2014-3-23
Hi all,
I'm going through a trial period of MATLAB and almost certainly will end up purchasing it, but I had one specific functionality question related to SUMIF tasks that I frequently use in Excel. If I have an Excel file with columns of both numerical data and text how in MATLAB would I perform SUMIF related calculations on that data?
As a concrete example let's say I have numerical data in the range A1:A1000 in Excel and text data representing state abbreviations ("TN", "MO", "CA", etc) in the range B1:B1000 in Excel. In Excel I could easily create a formula to sum all the numerical values when column B values equal "TN" or equal "TN" and "MO". How would I do this in MATLAB?
Also, the main reason I'm interested in doing these types of calcs in MATLAB instead of Excel is because I'm dealing with increasing large blocks of data in Excel and increasingly complex SUMIF calculations that are bogging down my spreadsheets.
Thanks,
JK

回答(1 个)

Image Analyst
Image Analyst 2014-3-23
You can use functions like strcmpi(), strfind(), etc. Then you can use if/else blocks or swtich blocks to do things based on which case you find.

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by