Substitute a value inside an array cell

2 views (last 30 days)
Krystian Meresinski
Krystian Meresinski on 31 Oct 2014
Edited: Geoff Hayes on 31 Oct 2014
Hello,
First thing to note: I'm not very experienced in Matlab. I'm currently involved in writing a software which might be a bit over my level - although I've learned a lot, there might be some basic knowledge I'm lacking.
Having this clarified, here's my question. I'm analising a lot of data na dmaking calculations that result in 2 vectors and one single value. This is the formula:
for i = 1:peaks-1
x_final_d(1,i) = abs(((((h_top-h/2)-b_D(i,1)))/a_D(i,1))-(((h_top-h/2)-b_D(i+1,1)))/a_D(i+1,1));
x_final_a(1,i) = abs(((((h_top-h/2)-b_A(i,1)))/a_A(i,1))-(((h_top-h/2)-b_A(i+1,1)))/a_A(i+1,1));
y_final = h_top-h/2;
end
Nothing very special, to be honest. For the x_final_a and x_final_d I should get results around 1000, +/-5%. For the reasons meantioned above, my code manages to make it properly in most cases, hovewer sometimes my filter is not tight enough and here and there I get values like 200, or so. Since I want to make an average and standard deviation, I should get rid of them. I want to substitute the with NaN and use nanmean and nanstd.
The code above is in custom function ( values ), which transfers data to another function ( full_code for the sake of reference), and the data from full_code is transfered to calculations, where I arrange them into a cell array which looks like this:
[1x8 double] [1x8 double] [-41.681792665672198] [1.002916975562337e+03] [1.002557764151239e+03] [ 2.076740522329561] [ 6.976575556945958]
I want to filter values from the first two cells. I use the following formula:
for n = 1:size(RESULT{j,1},2);
if RESULT{j,1}(1,n) > 1050
RESULT{j,1}(1,n) = NaN;
end
if RESULT{j,1}(1,n) < 950
RESULT{j,1}(1,n) = NaN;
end
end
for n = 1:size(RESULT{j,2},2);
if RESULT{j,2}(1,n) > 1050
RESULT{j,2}(1,n) = NaN;
end
if RESULT{j,2}(1,n) < 950
RESULT{j,2}(1,n) = NaN;
end
end
It's pretty simple. But, for some reason, it doesn't work, no matter if I put it in values or calculations. It doesn't give any error as well. When I tried to halt the funtion just before those commands and call them from the Command Window, I got an error that "Assignment has more non-singleton rhs dimensions than non-singleton subscripts". I'm aware that it has been discussed here (mostly by Walter Roberson), but I still can't really grasp the concept.
  1 Comment
Geoff Hayes
Geoff Hayes on 31 Oct 2014
Edited: Geoff Hayes on 31 Oct 2014
Krystian - when you say that it doesn't work, do you mean that your code does not replace the values in RESULT with NaN (at the appropriate position) or do you mean something else? Have you tried stepping through the code with the debugger to see what is going on?

Sign in to comment.

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!