Tag Archives: matlab

Debugging mode of MATLAB: dbstop if error

Because I wanted to debug MATLAB program in Terminal, I stumbled into DBStop if Error by mistake. This is a brief encounter, right?Who benefits from whom?I have to tell you more about it.
MATLAB programming has some common errors, such as dimension mismatch problems. If the error is inside the function, we usually need to run the program at least twice to solve the problem by debugging: the first time we run the program, after the program reports an error, we cannot debug because we have already quit the function in error; Before running the second time, manually set the breakpoint inside the failed function and run the program a second time for debugging.
In this case, a more efficient debugging method for MATLAB is to use dbStop if Error, rather than running the program multiple times and manually setting breakpoints. When MATLAB travel, MATLAB encountered errors will stop in the error of the line of code, directly can be debugged, do not need to run again.
There are also infrequent errors in MATLAB programming, where you don’t know where to set a breakpoint before the first run. In this case, dbStop if Error can be used as a precautionary measure.
Dbstop if Error can be set on the command line and in programs, as well as in the GUI. See the video below and the related web page.

Use of rep function in R

The official help document reads as follows:
Usage

rep(x, ...)

rep.int(x, times)

rep_len(x, length.out)

Arguments

x a vector (of any mode including a list) or a factor or (for rep only) A POSIXct or POSIXlt or Date object; or an S4 object containing such an object.
... further arguments to be passed to or from other methods. For the internal default method these can include:

times

An integer vector giving the (non-negative) number of times to repeat each element if of length length(x), Negative or NA values are an error.

length.out

The desired length of The output vector. Other inputs will be coerced into an integer vector and The first element taken. Ignored if NA or invalid

each

Non-negative integer. Each element of x is repeated Each times. Other inputs will be coerced into an integer vector and the first element taken As 1 if NA or invalid.

times

see ... .
length.out non-negative integer: the desired length of the output vector.

Rep functions with four parameters: the x vector or class vector of objects, each: x elements each repetitions, times: after each vector processing, if The Times is a single value, is the value of the whole after each repeat number of times, if it is equal to the vector x after each of the length of the vector, for each of the number of the elements of the repeat times each element in the same position, otherwise an error; Leng. out refers to the length of the final output of the vector processed by times. If it is longer than the generated vector, it is completed. That is, rep will take each parameter, generate a vector X1, and times will manipulate X1 to generate X2, lengthen. Out will manipulate X2 to produce the final output vector X3. Here is an example:
> Rep (1:4,times=c(1,2,3,4)) # and vector x equal length times mode
[1] 1 2 2 3 3 3 4 4 4 4
> Rep (1:4,times=c(1,2,3)) # non-equilong mode, Error
Error in rep(1:4,times=c(1,2,3)) : invalid 'times' argument
> Rep (1:4,each=2,times=c(1,2,3,4)) # is still non-equal length mode, because the vector after each has 8 bits, instead of 4 bits
Error in rep(1:4,each=2,times=c(1,2,3,4)) :
invalid 'times' argument
> Rep (1:4, times = c (1, 2, 3, 4)) # isometric model, I wrote to the o (╯/╰) o
[1] 1 2 2, 3, 3, 3, 4, 4 4 4
& gt; Rep (1:4,times=c(1,2,3,4),each=3) # repeat example, don't beat me
Error in rep(1:4,times=c(1,2,3,4),each=3) :
invalid 'times' argument
> Rep (1:4, each = 2, times = 8) # value correctly, times8 bit length vector
[1] 1 1 1 2 2 2 2 2 2 2, 3, 3 3 3 3 3 3 3 3 3, 3, 4, 4 4 4 4 4 4 4 4 4 4 4 4 4 4
& gt; Rep (1:4,each=2,times=1:8,len=3) # use of len, loop complement pay attention to
[1] 1 1 2
> Rep (1:4,each=2,times=3) # after each times
[1] 1 1 2 2 3 3 4 4 1 1 2 2 3 3 4 4 4 1 1 2 2 3 3 3 4 4
> Rep function over!

Reproduced in: https://www.cnblogs.com/business-analysis/p/3414997.html

matlab Error Subscript indices must either be real positive integers or logicals.

Matlab errors: Subscript Indices must either be real positive integers or Logicals.Subscript index must be of positive integer type or logical type

Cause of error: in the process of accessing the matrix (including vector, two-dimensional matrix, multidimensional array, same below), the index of the subscript either starts at 0 or has a negative number. Note: The syntax of MATLAB stipulates that the index of the matrix starts from 1, which is different from the habit of programming languages such as C.

Solution: Debug the program yourself and fix subscripts that are zero or negative.

I made a mistake when I was writing the program. I should have done the transpose of the matrix, but I forgot…

The errors dimensions of materials being qualified are not persistent


actually in matlab, we often encounter this problem, you have a look at the cause of the problem, you know what is the reason, but sometimes, pretty sure your program will be a problem, but the error, a run is a newspaper is very embarrassed, but it is not your program logic has a problem, mainly because the following error

Dimensions of matrices being concatenated are not consistent.


Cell2mat is matlab function is commonly used in a function, function is to convert the inside of the cell format digital into digital, in fact, when the inside of the cell number is expressed as a character to, such as’ 1 ‘, ‘2’, ‘3’ some of these characters, Cell2mat can also be converted characters into Numbers, but when these characters into ’10’, ’11’, ’12, the situation is complicated, the system will be an error, then say:

Error using cat

Dimensions of matrices being concatenated are not consistent.

Error in cell2mat (line 84)

m{n} = cat(1,c{:,n});

the solution to this problem is to use the function str2num to convert to number.





to solve this problem, a search on the Internet, are all conversion, but it seems that it is no use, I do not have time to find a solution to this problem, I will find a solution after busy with this topic research.

Mex compiler error handling in MATLAB and GCC installation in Ubuntu

I, MATLAB use mex error and GCC installation of a variety of problems to solve.

when I run my program, I notice that the “model” in the image below has not defne. (undefined)

access to a number of data, walk a lot of detours, only to find that the original is tex-mex file not compile.
then, compile tex-mex file, enter: tex-mex – setup
found an error again: “No supported compiler or the SDK was found.”

open baidu began to browse a variety of, dazzling methods… In fact, you only need to download the supported compiler or SDK.

is here, and since I’m ubuntu’s matlab for Linux, all I need to do is install GCC.

the steps are as follows:

sudo apt-get build-dep GCC

sudo apt-get  build-dep  gcc  

after the above method is used, the following situation occurs:

Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

enter the command:

sudo rm /var/lib/dpkg/lock
sudo dpkg --configure -a

when you run the initial command, the following situation occurs:

Unable to locate package
execute:

sudo apt-get update

start installation… Error:

, possibly due to network or other conflicts

ubuntu apt-get (You must put some ‘source’ URIs in your sources. List)
E: You must put some ‘source’ URIs in your sources. List

solution:

sudo vi /etc/apt/sources.list

open an editor and type:
copy code

deb-src http://archive.ubuntu.com/ubuntu trusty main restricted #Added by software-properties
deb-src http://gb.archive.ubuntu.com/ubuntu/ trusty restricted main universe multiverse #Added by software-properties
deb-src http://gb.archive.ubuntu.com/ubuntu/ trusty-updates restricted main universe multiverse #Added by software-properties
deb-src http://gb.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse #Added by software-properties
deb-src http://security.ubuntu.com/ubuntu trusty-security restricted main universe multiverse #Added by software-properties
deb-src http://gb.archive.ubuntu.com/ubuntu/ trusty-proposed restricted main universe multiverse #Added by software-properties

copy code
press Esc, enter: wq, then enter the command:

sudo apt-get update

: “E45: ‘readonly’ option is set (add! To override)

this is authority, set file into read-only permissions, as is known to all, read-only files need to be performed prior to such modification sudo, but have changed, how to enforce save?Geeks tell you! Just save and execute the following command:

:wq! The above command is to force save exit, and then you can!

try again to run sudo apt-get build-dep GCC, again failed.

method 2: enter the command: sudo apt-get install build-essential

sudo apt-get  install  build-essential

start installation, successful.

Windows of matlab in tex-mex compilation fails, go to https://ww2.mathworks.cn/support/requirements/supported-compilers.html directly download the corresponding matlab version of MinGW C/C + + 6.3.

Finally, enter MTALAB and enter met-setup


choose first.
raises a problem to be solved: train a decision tree, use the random forest classifier to extract the features of the input image, and output the frequency image??