Tuesday, March 24, 2015

R figure label expression

ylab=expression("UFP amount focus (# " ~ cm^-three ~ ")")

 ylab=expression(paste (PM[2.5], "mass focus (ug " ~ m^-three ~ ")"))

+labs(y=ylab)

Annotating subscript in R plots

I have to annotate one in every of my determine like this:

(b) PM2.5


And this can be a method to do it in R with ggplot2 package deal:

b ->
annotate("textual content", x=-three.5, y=zero.12, label=deparse(b),parse=TRUE)

Unsure concerning the particulars behind all of the parameters although. Because of BondedDust for answering this query.

Data and Questions: regression with factor variables

Hi my name is Kunal


I used to be taking the Knowledge Evaluation course by Jeff Leek on CourseEra.org. The video ' Regression with Issue Variables' was very helpful to me. Nevertheless, I'm a Matlab man and do not like R very a lot. So I did all of the evaluation in Matlab. The code is revealed right here:

http://matlabnewbie.blogspot.com/2014/01/matlab-code-regression-with-issue.html

and this is the video.


Matlab code: regression with factor variables

<!-- This HTML was auto-generated from MATLAB code. To make modifications, replace the MATLAB code and republish this doc. MovieData_Practice

Contents

  • Draw a scatter plot of boxoffice towards rating, grouped by score
  • Create dataset array, convert score to a nominal array
  • Queston 1 in Matlab
  • Query 2 in Matlab
  • Questions three in Matlab
  • 20/20
% Apply of Regression with categorical covariates
% By Segovia on 01/03/2014
clear;clc;shut;
load MovieData.mat

Draw a scatter plot of boxoffice towards rating, grouped by score

determine();
gscatter(rating,boxoffice, score,'bgr','x.o^');
title('boxoffice vs. rating, grouped by score')
""

Create dataset array, convert score to a nominal array

Film=dataset(boxoffice, rating,score);
Film.score=nominal(Film.score);

Queston 1 in Matlab

%Match a regression mannequin
% in 2013a model, use perform LinearModel.match
% in 2013b model, use perform fitlm
match=LinearModel.match(Film, 'rating~score')

match =


Linear regression mannequin:
rating ~ 1 + score

Estimated Coefficients:
Estimate SE tStat pValue
(Intercept) sixty seven.sixty five 7.1933 9.4046 1.7256e-sixteen
rating_PG -12.593 7.8486 -1.6045 zero.11093
rating_PG-thirteen -eleven.815 7.4113 -1.5941 zero.11323
rating_R -12.02 7.4755 -1.6079 zero.11017


Variety of observations: one hundred forty, Error levels of freedom: 136
Root Imply Squared Error: 14.four
R-squared: zero.0199, Adjusted R-Squared -zero.00177
F-statistic vs. fixed mannequin: zero.918, p-worth = zero.434

Query 2 in Matlab

%Match a regression mannequin and use "R" as reference degree in score
Movie2=Film;
Movie2.score=reorderlevels(Movie2.score, 'R','G','PG','PG-thirteen');
fit2=LinearModel.match(Movie2,'rating~score')

fit2 =


Linear regression mannequin:
rating ~ 1 + score

Estimated Coefficients:
Estimate SE tStat pValue
(Intercept) fifty five.sixty three 2.0346 27.342 four.0302e-fifty seven
rating_G 12.02 7.4755 1.6079 zero.11017
rating_PG -zero.57286 three.7411 -zero.15313 zero.87852
rating_PG-thirteen zero.20538 2.7062 zero.075893 zero.93962


Variety of observations: one hundred forty, Error levels of freedom: 136
Root Imply Squared Error: 14.four
R-squared: zero.0199, Adjusted R-Squared -zero.00177
F-statistic vs. fixed mannequin: zero.918, p-worth = zero.434

Questions three in Matlab

anova(match)

ans =

SumSq DF MeanSq F pValue
score 570.12 three one hundred ninety.04 zero.91818 zero.43398
Error 28149 136 206.ninety eight

20/20

[~,~,st]=anova1(Movie2.rating, Movie2.score,'off');
[c,m,h,nms]=multcompare(st,'show','off','ctype','hsd')

c =

1.0000 2.0000 -31.2248 -12.0200 7.1848
1.0000 three.0000 -9.0380 zero.5729 10.1837
1.0000 four.0000 -7.1578 -zero.2054 6.7470
2.0000 three.0000 -7.5703 12.5929 32.7560
2.0000 four.0000 -7.2254 eleven.8146 30.8546
three.0000 four.0000 -10.0553 -zero.7782 eight.4988


m =

fifty five.6300 2.0346
sixty seven.6500 7.1933
fifty five.0571 three.1394
fifty five.8354 1.7844


h =

[]


nms =

'R'
'G'
'PG'
'PG-thirteen'


Revealed with MATLAB® R2013a
-->

windrose plot by sigmaplot and matlab

I used two strategies to plot wind course and velocity knowledge: Sigmaplot and Matlab.
To appropriately present the wind is blowing from the diploma, say 10 diploma, I have to verify the 'clock sensible' choice. In any other case the path can be mistaken.
Once I used the wind_rose.m, which is downloaded from this hyperlink:
http://www.mathworks.com/matlabcentral/fileexchange/17748-windrose
the right method is to make use of D-one hundred eighty, and set the 'dtype' to 'meteo'.

This manner the 2 plots made by two totally different strategies can be constant and proper.

Matlab: Remove a cell element from a cell array

Just like the tactic to take away undesirable component in a matrix, which is mentioned in particulars in one other publish (http://matlabnewbie.blogspot.com/2009/07/matlab-take away-all-unwatned-parts-in.html), the undesirable cell factor could be faraway from a cell array. The one distinction is that the strcmp perform ought to be used to determine the place all these undesirable cells are.

The next instance exhibits learn how to take away the cell 'good' from the cell array a, to be by some means humble.

a=['this','is','a','good','matlab','blog'];                 % create a cell array
a=a(~strcmp(a, 'good'))                                                          % take away the 'good' cell

End result seems to be like this:


a = 

    'this'    'is'    'a'    'matlab'    'weblog'

Set the properties of a dataset array in Matlab

The % signal, %, can be utilized within the matlab code so as to add explanatory info to the code. Equally, we will add explanatory info to a dataset array, through the use of the dataset array properties. The set perform can be utilized to assign values to the dataset property, and the get perform can be utilized to entry these info.

DS=dataset(...) % a dataset array is constructed
DS=set(DS, 'Description', 'No matter can describe the dataset might be put right here');
get(DS) % present dataset array properties
abstract(DS) % additionally present dataset array properties 

The 'Description' could be changed with different properties that are displayed by the get perform. 

Convert a dataset to matrix

For the only case when the dataset solely incorporates numbers, this double perform can be utilized to transform a dataset to matrix, or a vector if there is just one variable within the dataset:

m=double(ds)

Two useful Excel tricks

I used to be utilizing Excel at present and discover that I have to do two issues. The primary one is to routinely alternate row colours (one shaded, one white), so I searched on-line and located this tutorial very helpful.

http://www.techonthenet.com/excel/questions/cond_format2.php


And the opposite factor I want to do is to create an inventory from knowledge validation, so in every cell of 1 column, I can choose the automotive makers. And I want to use the subsequent column to report the automotive mannequin, which imply the second listing depends on the number of earlier cell's enter. I searched on-line and located that it's referred to as : dependent listing for knowledge validation. This is the tutorial that I adopted:

http://www.contextures.com/xlDataVal02.html

Very useful!

Show the variable names of a dataset

listing = get (dataset, 'VarNames')

Matlab surface fitting: why and how

Lately I come throughout an issue like this in my work:

Tow inputs, or say variables, decide the worth of 1 output. z=f(x,y), however I'm not positive what the perform seem like explicitly. So I did numerous measurements and by the top I obtained three units of knowledge: 7 x values, 21 y values, and 147 corresponding z values. The floor becoming is the tactic that may assist me discover the specific type of perform z=f(x,y). And I used the Floor Becoming Device in MATLAB to do that.

This software has a really consumer-pleasant interface, so not a lot rationalization is required right here.
Display shot of Floor Becoming Toll

Link Exchange

This weblog has ~5000 web page views every month. I'm very happy to change hyperlinks with you in case you are the proprietor of a weblog/web site which focuses on the engineering, science, and know-how.

Depart me a remark in case you are and I'll reply in a well timed method.

Matlab Statistic Tool Box regstats model trick

Simply discovered this trick as we speak.
When utilizing:

regstats(y,x)

Matlab will use the linear mannequin y=ax+b mannequin to suit the info and calculate all related statistical parameters.

However typically we need to repair the development line by way of zero, (zero,zero). In these case, this trick will assist:

regstats(y,x,1)

Now Matlab will use the linear mannequin y=ax mannequin to suit the info and calculate all related statistical parameters.

Do not know why. However it's examined on R2010b model and confirmed by evaluating with Excel calculation outcomes.

batch processing multiple files in matlab using for loop and uigetfile function

Lately I acquired a bunch of information which have the identical format and construction and I want to make use of Matlab to course of every file, which suggests finishing up the identical calculation process to every file. This is the code I created to do that.

% Import the file names
% The *.csv parameter signifies that solely csv information can be proven within the file choice window
% Activate the MultiSelect parameter in order that a number of information may be chosen on the similar time
[filename, ~,~]=uigetfile(*.csv, 'MultiSelect', 'on');
% now use a for loop to hold out similar calculation process to every file
% the process_each_file is a perform that does the calculation process
% earlier than utilizing the for loop, let's outline an area to retailer all of the outputs from every file calculation first
Re=zeros(size(filename),1);
for i = 1 : size(filename)
     Re(i)=process_each_file ( filename(i))
finish




remove outliers in Matlab

This is the code i wrote lately to take away the outliers from the experimental knowledge. Something outdoors the vary from Q1-1.5IQR to Q3+1.5IQR might be eliminated.

a=[10 11 13 19 9 8 11 14 12 17 1 2 10 11 13 12 12 11 10];
IQR=iqr(a);
lowr=prctile(a,25)-1.5*IQR;
highr=prctile(a,seventy five)+1.5*IQR;
new_a=a(a>lowr & a<highr);

Why would this happen???

Once I copy and paste a date and time from one MS Excel file to a different, the worth was stored the identical however after formatting it to the Time format, the date went virtually four years again!!!


Simulink model of Continuous Stirred-Tank Reactor in series

This is a easy Simulink mannequin I created at the moment. This mannequin simulates the focus in three Steady Stirred-Tank Reactor (CSTR) in a row and the way these focus values affected by the influent focus. Typically the CSTR can also be referred to as properly-combined steady stream via reactor.

The S-perform of this CSTR mannequin is proven under.


perform [sys, x0 str, ts]=cstr_sfcn(t,x,u,flag,Cinit)
change flag
    case zero %initialize
        str=[];
        ts=[0 0];
        x0=Cinit;
        
        s=simsizes;
        s.NumContStates=1;
        s.NumDiscStates=zero;
        s.NumOutputs=1;
        s.NumInputs=1;
        s.DirFeedthrough=zero;
        s.NumSampleTimes=1;
        
        sys=simsizes(s);
        
    case 1 % derivatives


        sys=cstr(t,x,u);
    
    case three %output
        sys=x;
        
    case 2 four 9
        sys=[];
    in any other case
        error(['unhandled flag=', num2str(flag)])
finish


And under is the perform of the reactor.


perform dx=cstr(t, x, u)
Ca=x;
dCa=zero.2*(u-Ca);
dx=dCa;

The Simulink mannequin seems like this:



All the three tanks has the identical traits, besides the preliminary concentrations have been totally different.
C1(zero)=5, C2(zero)=three, and C3(zero)=1. And the influent focus was simulated by the heart beat generator. The simulation outcomes is proven under.





Set marker edge width in Matlab figures

A few days in the past, I plotted about twenty figures and was making an attempt to set the markers with thicker edge. This might be very straightforward if it was in Excel: simply change the 'Marker Line Fashion' within the 'Format knowledge collection' tab. Nevertheless, it was sort troublesome to do in Matlab. At the very least I did not get an excellent answer from the google outcomes on that day.

At the moment I occurred to seek out the answer once I was enjoying with Matalb only for enjoyable. The very fact is that the 'Marker Edge Width' is definitely outlined by the 'LineWidth', even when the plot doesn't use a line to attach the markers..

t=[1:5];
plot(t,sin(t), 's', 'Markersize', 20,'LineWidth', 5)  



Concatenate text and convert to numbers in Excel

I've an extended Excel file which hold the date, month, yr, hour, minute, and second in separate columns (determine 1). I need to use just one column to current the time, so it will be simpler to plot the time as x-axis. Right here is the perform I utilized in cell G2:

=VALUE(CONCATENATE(A2,"/",B2,"/",C2," ",D2,":",E2,":", F2))


The Worth perform convert the textual content into numbers.
The Concatenate perform connects all of the textual content and convert them into one string.

Online resources to learn Matlab

Whereas we right here at Matlabtips respect you visiting our weblog, we want to take one submit and introduce a couple of different nice on-line assets for rookies and superior customers alike to study extra about Matlab. We hope that you simply … Proceed studying

There are two types of data scientists – those who cluster and those who don’t

As we speak, we're fortunate to have Jesse Marshall as a visitor blogger on knowledge evaluation. Jesse is a PhD scholar at Stanford, engaged on analyzing the collective conduct of lots of of neurons as they course of info within the dwelling mind.  People have … Proceed studying

Variable Scope: Memory Spaces in Matlab

On this submit, we discuss about variables. Particularly, we'll … Proceed studying →

Set the properties of a dataset array in Matlab

The percent sign, %, can be used in the matlab code to add explanatory information to the code. Similarly, we can add explanatory information to a dataset array, by using the dataset array properties. The set function can be used to assign values to the dataset property, and the get function can be used to access these information.

DS=dataset(...) % a dataset array is constructed
DS=set(DS, 'Description', 'Whatever can describe the dataset can be put here');
get(DS) % show dataset array properties
summary(DS) % also show dataset array properties 

The 'Description' can be replaced with other properties which are displayed by the get function. 

Convert a dataset to matrix

For the simplest case when the dataset only contains numbers, this double function can be used to convert a dataset to matrix, or a vector if there is only one variable in the dataset:

m=double(ds)

Two useful Excel tricks

I was using Excel today and find that I need to do two things. The first one is to automatically alternate row colors (one shaded, one white), so I searched online and found this tutorial very useful.

http://www.techonthenet.com/excel/questions/cond_format2.php


And the other thing I would like to do is to create a list from data validation, so in each cell of one column, I can select the car makers. And I would like to use the next column to record the car model, which mean the second list is dependent on the selection of previous cell's input. I searched online and found that it is called : dependent list for data validation. Here's the tutorial that I followed:

http://www.contextures.com/xlDataVal02.html

Very helpful!

Show the variable names of a dataset

list = get (dataset, 'VarNames')

Matlab surface fitting: why and how

Recently I come across a problem like this in my work:

Tow inputs, or say variables, determine the value of one output. z=f(x,y), but I am not sure what the function look like explicitly. So I did a lot of measurements and by the end I got three sets of data: 7 x values, 21 y values, and 147 corresponding z values. The surface fitting is the method that can help me find the explicit form of function z=f(x,y). And I used the Surface Fitting Tool in MATLAB to do this.

This tool has a very user-friendly interface, so not much explanation is needed here.
Screen shot of Surface Fitting Toll

Link Exchange

This blog has ~5000 page views each month. I am more than happy to exchange links with you if you are the owner of a blog/website which focuses on the engineering, science, and technology.

Leave me a comment if you are interested and I will respond in a timely manner.

Matlab Statistic Tool Box regstats model trick

Just found this trick today.
When using:

regstats(y,x)

Matlab will use the linear model y=ax+b model to fit the data and calculate all relevant statistical parameters.

But sometimes we want to fix the trend line through zero, (0,0). In these case, this trick will help:

regstats(y,x,1)

Now Matlab will use the linear model y=ax model to fit the data and calculate all relevant statistical parameters.

Don't know why. But it is tested on R2010b version and confirmed by comparing with Excel calculation results.

batch processing multiple files in matlab using for loop and uigetfile function

Recently I got a bunch of files that have the same format and structure and I need to use Matlab to process each file, which means carrying out the same calculation procedure to each file. Here's the code I created to do this.

% Import the file names
% The {*.csv} parameter indicates that only csv files will be shown in the file selection window
% Turn on the MultiSelect parameter so that multiple files can be selected at the same time
[filename, ~,~]=uigetfile({*.csv}, 'MultiSelect', 'on');
% now use a for loop to carry out same calculation procedure to each file
% the process_each_file is a function that does the calculation procedure
% before using the for loop, let's define a space to store all the outputs from each file calculation first
Re=zeros(length(filename),1);
for i = 1 : length(filename)
     Re(i)=process_each_file ( filename(i))
end




remove outliers in Matlab

Here's the code i wrote recently to remove the outliers from the experimental data. Anything outside the range from Q1-1.5IQR to Q3+1.5IQR will be removed.

a=[10 11 13 19 9 8 11 14 12 17 1 2 10 11 13 12 12 11 10];
IQR=iqr(a);
lowr=prctile(a,25)-1.5*IQR;
highr=prctile(a,75)+1.5*IQR;
new_a=a(a>lowr & a<highr);

Why would this happen???

When I copy and paste a date and time from one MS Excel file to another, the value was kept the same but after formatting it to the Time format, the date went almost 4 years back!!!


Simulink model of Continuous Stirred-Tank Reactor in series

Here's a simple Simulink model I created today. This model simulates the concentration in three Continuous Stirred-Tank Reactor (CSTR) in a row and how these concentration values affected by the influent concentration. Sometimes the CSTR is also called well-mixed continuous flow through reactor.

The S-function of this CSTR model is shown below.


function [sys, x0 str, ts]=cstr_sfcn(t,x,u,flag,Cinit)
switch flag
    case 0 %initialize
        str=[];
        ts=[0 0];
        x0=Cinit;
        
        s=simsizes;
        s.NumContStates=1;
        s.NumDiscStates=0;
        s.NumOutputs=1;
        s.NumInputs=1;
        s.DirFeedthrough=0;
        s.NumSampleTimes=1;
        
        sys=simsizes(s);
        
    case 1 % derivatives


        sys=cstr(t,x,u);
    
    case 3 %output
        sys=x;
        
    case {2 4 9}
        sys=[];
    otherwise
        error(['unhandled flag=', num2str(flag)])
end


And below is the function of the reactor.


function dx=cstr(t, x, u)
Ca=x;
dCa=0.2*(u-Ca);
dx=dCa;

The Simulink model looks like this:



All of the three tanks has the same characteristics, except the initial concentrations were different.
C1(0)=5, C2(0)=3, and C3(0)=1. And the influent concentration was simulated by the pulse generator. The simulation results is shown below.





Set marker edge width in Matlab figures

A couple of days ago, I plotted about twenty figures and was trying to set the markers with thicker edge. This would be very easy if it was in Excel: just change the 'Marker Line Style' in the 'Format data series' tab. However, it was kind difficult to do in Matlab. At least I didn't get a good solution from the google results on that day.

Today I happened to find the solution when I was playing with Matalb just for fun. The fact is that the 'Marker Edge Width' is actually defined by the 'LineWidth', even when the plot does not use a line to connect the markers..

t=[1:5];
plot(t,sin(t), 's', 'Markersize', 20,'LineWidth', 5)  



Concatenate text and convert to numbers in Excel

I have a long Excel file which keep the date, month, year, hour, minute, and second in separate columns (figure 1). I want to use only one column to present the time, so it would be easier to plot the time as x-axis. Here is the function I used in cell G2:

=VALUE(CONCATENATE(A2,"/",B2,"/",C2," ",D2,":",E2,":", F2))


The Value function convert the text into numbers.
The Concatenate function connects all the text and convert them into one string.

remove any rows that contains a specific number in Matlab

In this post, I am trying to solve the problem given in the comments of one of the old post.
Here's the problem, if I understand it correctly:

a =

     1     2     3     4     5
     2     3     4   -99     6
     3     4     5     6     7
     4   -99     6     7     8
     5     6     7     8     9

How to remove all the rows that contains the number -99, in this case, the row #2 and #4?

And here's the code I wrote to do this job:

[rows col]=size(a); %count the number of rows and columns of matrix a
j=0; %initialize a counter;
for i=1: rows
    if sum(a(i,:)~=-99)==col; %This determines if the row has -99 or not, if not, do nothing
    else     %shift all of the rest of the rows up one row
        for m=i: rows-1; 
        a(m,:)=a(m+1,:);
        end
        j=j+1; %count how many rows has -99, which equals how many times the rows has been shifted up 
    end
end
b=a((1:rows-j),:); %get rid of the last j rows


The result is:



b =


     1     2     3     4     5
     3     4     5     6     7
     5     6     7     8     9



I hope this can work for you, Winifred. Thanks for your comments!

Online resources to learn Matlab

While we here at Matlabtips appreciate you visiting our blog, we would like to take one post and introduce a few other great online resources for beginners and advanced users alike to learn more about Matlab. We hope that you … Continue reading

There are two types of data scientists – those who cluster and those who don’t

Today, we are lucky to have Jesse Marshall as a guest blogger on data analysis. Jesse is a PhD student at Stanford, working on analyzing the collective behavior of hundreds of neurons as they process information in the living brain.  Humans have … Continue reading

Error Handling – Using Try and Catch

Typically when using Matlab, if the program encounters some bug, you will hear the system bell and see the dreaded red text show up in the command window. So what do you do if you absolutely need your programs to … Continue reading

Variable Scope: Memory Spaces in Matlab

For this post, we are glad to welcome Nicholas as a contributor to Matlabtips.com. If you are interested in writing a guest post, please don’t hesitate to contact us.  In this post, we talk about variables. In particular, we will … Continue reading

Happy new 2015

It is an established tradition that blogs will look back on new year and discuss past achievements. I also felt it was a good opportunity to share with you some results from this website statistics and suggest what the next … Continue reading

Auto-contrast: an optimization example where Matlab beats Matlab

For this post, we are glad to have Thierry as a guest blogger. He talks about an optimisation example he recently encountered that is a good indirect example of ‘inlining‘. As my first post here, I will first describe a standard … Continue reading

Debugging in Matlab

You’ve just finished writing your latest and greatest Matlab program. You’re sure this program will solve all the world’s (or at the very least all of your) problems. Just as you run your program, you see the dreaded red error … Continue reading

Logical operations and logical indexing in Matlab

In this post, we talk about logical operations but also how to use your Matlab skills to analyze your shopping expenses (Yes, we are all absolute nerds and love it). You will learn how to use logical operations to search … Continue reading

How and when to convert between data types

In this post, we talk about data types and extend on our previous post on the matter. You will learn how to convert between them but more importantly when and why you should consider such things. As often, we delve … Continue reading

ICA demystified

This post has been on the back of my mind for quite some time, ever since I wrote about Principal Component Analysis. Independent Component Analysis or ICA is an algorithm to extract underlying structure hidden in multi-dimensional datasets. As for … Continue reading

Modeling with ODEs in Matlab – Part 5B

And so we reach the end. We will wrap up this series with a look at the fascinating Lorenz Attractor. Like the logistic map of the previous lesson, the Lorenz Attractor has the structure and behavior of a complex system. … Continue reading

Modeling with ODEs in Matlab – Part 5A

We are going to wrap up this tutorial series with a fun exploration of complex systems. Complex systems behave in unpredictable ways. This often makes it difficult to design and use models to examine their behavior. In this lesson we … Continue reading

Modeling with ODEs in Matlab – Part 4B

Welcome to Modeling with ODEs in Matlab – Part 4B! The previous post, Part 4A, introduced the idea of fitting ODE coefficients to empirical data. We saw that proper use of the nlinfit function combined with ode45 or ode15s allows … Continue reading

Sunday, March 22, 2015

Random Numbers in Matlab – Part III

That is the ultimate submit in our collection on random numbers in Matlab. Within the first submit, we mentioned primary random quantity features, and within the second submit, we mentioned the management of random quantity era in Matlab and options … Proceed studying →

Thursday, March 19, 2015

Random Numbers in Matlab – Part II

That is my second publish in our collection on random numbers in Matlab. The primary publish may be discovered right here. On this publish, I'll clarify the way to management the random quantity era features in Matlab and talk about options for tasks … Proceed studying →

Monday, March 16, 2015

remove any rows that contains a specific number in Matlab

On this submit, I'm making an attempt to unravel the issue given within the feedback of one of many previous submit.
This is the issue, if I perceive it appropriately:

a =

     1     2     three     four     5
     2     three     four   -ninety nine     6
     three     four     5     6     7
     four   -ninety nine     6     7     eight
     5     6     7     eight     9

Methods to take away all of the rows that accommodates the quantity -ninety nine, on this case, the row #2 and #four?

And this is the code I wrote to do that job:

[rows col]=measurement(a); %rely the variety of rows and columns of matrix a
j=zero; %initialize a counter;
for i=1: rows
    if sum(a(i,:)~=-ninety nine)==col; %This determines if the row has -ninety nine or not, if not, do nothing
    else     %shift all the remainder of the rows up one row
        for m=i: rows-1; 
        a(m,:)=a(m+1,:);
        finish
        j=j+1; %rely what number of rows has -ninety nine, which equals what number of occasions the rows has been shifted up 
    finish
finish
b=a((1:rows-j),:); %eliminate the final j rows

The result's:


b =

     1     2     three     four     5
     three     four     5     6     7
     5     6     7     eight     9



I hope this could be just right for you, Winifred. Thanks in your feedback!