Excel SUM IF in MATLAB?

9 views (last 30 days)
Jared
Jared on 23 Mar 2014
Answered: Image Analyst on 23 Mar 2014
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

Answers (1)

Image Analyst
Image Analyst on 23 Mar 2014
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.

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!