Finding mean of ascii values in a string MATLAB

The string I am given is as follows:

scrap1 = 
a le h
ke fd 
zyq  b
 ner i

You'll notice there are 2 blank spaces indicating a space (ASCII 32) in each row. I need to find the mean ASCII value in each column without taking into account the spaces (32). So first I would convert to with double(scrap1) but then how do I find the mean without taking into account the spaces?

Answers


If it's only the ASCII 32 you want to omit:

d = double(scrap1);
result = mean(d(d~=32)); %// logical indexing to remove unwanted value, then mean

You can remove the intermediate spaces in the string with scrap1(scrap1 == ' ') = ''; This replaces any space in the input with an empty string. Then you can do the conversion to double and average the result. See here for other methods.


Probably, you can use regex to find the space and ignore it. "\s"

findSpace = regexp(scrap1, '\s', 'ignore')

% I am not sure about the ignore case, this what comes to my mind. but u can read more about regexp by typying doc regexp.


Need Your Help

How do you pass a float[] array between activities in android?

android arrays android-intent

class1.java has creates a float[] array that is need to have in class2.java. How do you do this? The float[] is points. Here is an example code:

Swift JSON data on TableView lags

ios json swift uitableview

I have an issue with my TableView displaying JSON data. When it is displayed, it currently lags whenever I scroll up and down. I know that I have to use the Grand Central Dispatch methods (GCD) for...