How to find the peakpoint in z direction after fitting a 3D surface in matlab - matlab

I have fitted the 3D surface and just want to know how to find the max value of z direction after fitting, not the max value that I gave, it would be just noise. The code can be seen as followed.
x=[0 6.8 18.6 21.3 3 12.5 13 20.7 17.7 20.8 1.1 6.3 13.2 3.4 3.5 18.9 11.3 13.1];
y=[1.7 1.1 0.8 1.2 3.1 3 3.1 4.2 4.1 5.8 6.4 5.8 7.4 5.3 5.9 9.7 7.6 10.7];
z=[0.59 0.58 0.53 1.25 1.26 0.2 0.18 0.14 0.64 0. 1.06 0.73 0.15 0.15 0.1 0.08 0.17 0.8];
scatter3(x,y,z)
x=x';
y=y';
z=z';
hold on
Z=[ones(length(x),1),x,y,x.^2,x.*y,y.^2,x.^3,x.^2.*y,x.*y.^2,y.^3];
A=Z\z;
X=min(x)-1:0.2:max(x)+1;
Y=min(y)-1:(max(y)-min(y)+2)/(length(X)+1):max(y)+1;
[x y]=meshgrid(X,Y);
z=A(1)+A(2)*x+A(3)*y+A(4)*x.^2+A(5)*x.*y+A(6)*y.^2+A(7)*x.^3+A(8)*x.^2.*y+A(9)*x.*y.^2+A(10)*y.^3;
mesh(x,y,z)

Related

Solve function returning symbol

I am trying to use the MATLAB Symbolic Math Toolbox to solve simple equations, but I am not receiving the expected/desired result.
I'm using Windows 10, and this is the output of entering ver into the Command Window:
MATLAB Version: 9.6.0.1335978 (R2019a) Update 8
MATLAB License Number: STUDENT
Operating System: Microsoft Windows 10 Pro Version 10.0 (Build 19041)
Java Version: Java 1.8.0_181-b13 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------
MATLAB Version 9.6 (R2019a)
Simulink Version 9.3 (R2019a)
Control System Toolbox Version 10.6 (R2019a)
Curve Fitting Toolbox Version 3.5.9 (R2019a)
DSP System Toolbox Version 9.8 (R2019a)
Data Acquisition Toolbox Version 4.0 (R2019a)
Image Processing Toolbox Version 10.4 (R2019a)
Instrument Control Toolbox Version 4.0 (R2019a)
Optimization Toolbox Version 8.3 (R2019a)
Parallel Computing Toolbox Version 7.0 (R2019a)
Signal Processing Toolbox Version 8.2 (R2019a)
Simulink Control Design Version 5.3 (R2019a)
Statistics and Machine Learning Toolbox Version 11.5 (R2019a)
Symbolic Math Toolbox Version 8.3 (R2019a)
According to the in-app documentation, the solve function should follow this syntax:
syms x
eqn = sin(x) == 1;
solx = solve(eqn, x)
And the expected output from this is:
solx =
pi/2
However, when I run the same commands I receive:
>> syms x
>> eqn = sin(x) == 1;
>> solx = solve(eqn, x)
solx =
x
I have tried a number of even simpler equations with the same result (receiving symbol instead of a numerical value).
What am I doing incorrectly?
Thanks in advance.
As discussed in the comments, your MATLAB installation does not seem to use the function in ...\toolbox\symbolic\symbolic\solve.m when a solve command is issued; instead, an unrelated function provided by the maple toolbox is used, leading to some confusion. This issue can be solved by reordering the MATLAB search path:
p=path();
path(p,'C:\Program Files\MATLAB\R2019a\toolbox\maple');

What are the available precision of system clock for Java 8 and 11 in each platform (windows, macOS, Linux)?

I'm aware that Java 8 (Oracle) system Clock implementation is limited to milliseconds at most, and that Java 9+ fixed that so in principle could get up to nanoseconds from the underlying clock. But then the underlying clock resolution may be ticking in steps of 1000ns or 100ns or 10ms, etc.
I know that in macOS Mojave the Java 8 clock give me resolution of 1ms and with Java 11 the resolution is 1ns
System.out.println(Instant.now()); // macOS Mojave Java 8 : 2019-11-15T09:04:32.714Z
System.out.println(Instant.now()); // macOS Mojave Java 11: 2019-11-15T09:01:30.867915Z
Is there a list of the actual precision / accuracy / resolutions per Java platform and OS?
Java 8
Up to milliseconds
Windows 10:
Linux 2.4: 10 ms (if I interpret right time(7))
Linux 2.6:
macOS Mojave: 1ms resolution
Java 11
Windows 10:
Linux 2.4:
Linux 2.6:
macOS Mojave: 1ns resolution

Entering a group of numbers sequentially in specific positions in a matrix using Matlab

I have a matrix and I want to enter a group of numbers in this matrix sequentially. Here is an example:
Suppose that:
x = [1 2 3 4 5 6 7] % Group of numbers
A = % The matrix
1.1 2.2 3.1 4.1 5.3 1.2 1.3
3.1 4.2 1.1 7.4 5.6 2.2 1.3
1.4 5.2 4.3 2.2 4.3 3.2 1.3
1.6 3.2 6.3 2.1 2.6 7.2 1.3
6.1 1.3 9.4 4.2 3.3 1.2 1.3
2.5 4.2 3.2 5.1 6.7 1.2 1.3
What I am trying to do is to find a way using loops to enter the group of numbers stored in x to be in the following way:
A = % The matrix
1.1 2.2 3.1 4.1 5.3 1.2 1.3 1.1 2.2 3.1 4.1 5.3 1.2 1.3 1.1 2.2 3.1 4.1 5.3 1.2 1.3
1.0 2.0 3.0 4.0 5.0 6.0 7.0 3.1 4.2 1.1 7.4 5.6 2.2 1.3 3.1 4.2 1.1 7.4 5.6 2.2 1.3
1.4 5.2 4.3 2.2 4.3 3.2 1.3 1.0 2.0 3.0 4.0 5.0 6.0 7.0 1.4 5.2 4.3 2.2 4.3 3.2 1.3
1.6 3.2 6.3 2.1 2.6 7.2 1.3 1.6 3.2 6.3 2.1 2.6 7.2 1.3 1.0 2.0 3.0 4.0 5.0 6.0 7.0
6.1 1.3 9.4 4.2 3.3 1.2 1.3 6.1 1.3 9.4 4.2 3.3 1.2 1.3 6.1 1.3 9.4 4.2 3.3 1.2 1.3
2.5 4.2 3.2 5.1 6.7 1.2 1.3 2.5 4.2 3.2 5.1 6.7 1.2 1.3 2.5 4.2 3.2 5.1 6.7 1.2 1.3
As you can notice the group of numbers (from 1.0 to 7.0) moves down (row by row) till the end of the matrix. At each move the matrix dimension increases as well. I believe that I should define the matrix dimension first.
To do so, I found that multiplying the matrix columns by the number of rows
I will get the new matrix dimension which in this case will be 7 (rows) x 49 (columns).
I need to know how to create such a matrix automatically using for loop or any other possible way.
Thanks in advance.
Use repmat in order to concat 3 copies of your matrix horizontally.
Use the Matlab's assignment syntax: A(row,col:col+length(x)-1) in order to copy x into the desired row and col.
Code example:
outA = repmat(A,1,3); %replicate A
outA(2,1:length(x)) = x; %inserts x into the beginning of the 2nd row
outA(4,size(outA,2)-length(x)+1:end) = x; %inserts x into the end of the 4th row
Results:
outA =
1.1 2.2 3.1 4.1 5.3 1.2 1.3 1.1 2.2 3.1 4.1 5.3 1.2 1.3 1.1 2.2 3.1 4.1 5.3 1.2 1.3
1.0 2.0 3.0 4.0 5.0 6.0 7.0 3.1 4.2 1.1 7.4 5.6 2.2 1.3 3.1 4.2 1.1 7.4 5.6 2.2 1.3
1.4 5.2 4.3 2.2 4.3 3.2 1.3 1.4 5.2 4.3 2.2 4.3 3.2 1.3 1.4 5.2 4.3 2.2 4.3 3.2 1.3
1.6 3.2 6.3 2.1 2.6 7.2 1.3 1.6 3.2 6.3 2.1 2.6 7.2 1.3 1.0 2.0 3.0 4.0 5.0 6.0 7.0
6.1 1.3 9.4 4.2 3.3 1.2 1.3 6.1 1.3 9.4 4.2 3.3 1.2 1.3 6.1 1.3 9.4 4.2 3.3 1.2 1.3
2.5 4.2 3.2 5.1 6.7 1.2 1.3 2.5 4.2 3.2 5.1 6.7 1.2 1.3 2.5 4.2 3.2 5.1 6.7 1.2 1.3

multiple knitr kables by group

for a given dataset, I want to print group-wise kables with group names as caption in an rmarkdown.
say this is my_document:
library(magrittr)
library(dplyr)
library(knitr)
iris %>%
group_by(Species) %>%
slice(1:10) %>%
do(kables = kable(., caption = .$Species[1])) %$%
kables %>%
lapply(print)
i call rmarkdown::render("my_document.R") to generate the markdown output.
the problem now is that my kables appear in comments, but not as rendered kables:
## Table: setosa
##
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## ------------- ------------ ------------- ------------ --------
## 5.1 3.5 1.4 0.2 setosa
## 4.9 3.0 1.4 0.2 setosa
## 4.7 3.2 1.3 0.2 setosa
## 4.6 3.1 1.5 0.2 setosa
## 5.0 3.6 1.4 0.2 setosa
## 5.4 3.9 1.7 0.4 setosa
## 4.6 3.4 1.4 0.3 setosa
## 5.0 3.4 1.5 0.2 setosa
## 4.4 2.9 1.4 0.2 setosa
## 4.9 3.1 1.5 0.1 setosa
##
##
## Table: versicolor
##
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## ------------- ------------ ------------- ------------ -----------
## 7.0 3.2 4.7 1.4 versicolor
## 6.4 3.2 4.5 1.5 versicolor
## 6.9 3.1 4.9 1.5 versicolor
## 5.5 2.3 4.0 1.3 versicolor
## 6.5 2.8 4.6 1.5 versicolor
## 5.7 2.8 4.5 1.3 versicolor
## 6.3 3.3 4.7 1.6 versicolor
## 4.9 2.4 3.3 1.0 versicolor
## 6.6 2.9 4.6 1.3 versicolor
## 5.2 2.7 3.9 1.4 versicolor
##
##
## Table: virginica
##
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## ------------- ------------ ------------- ------------ ----------
## 6.3 3.3 6.0 2.5 virginica
## 5.8 2.7 5.1 1.9 virginica
## 7.1 3.0 5.9 2.1 virginica
## 6.3 2.9 5.6 1.8 virginica
## 6.5 3.0 5.8 2.2 virginica
## 7.6 3.0 6.6 2.1 virginica
## 4.9 2.5 4.5 1.7 virginica
## 7.3 2.9 6.3 1.8 virginica
## 6.7 2.5 5.8 1.8 virginica
## 7.2 3.6 6.1 2.5 virginica
so how do i get rendered kables by group in my markdown document?
You need to specify results="asis" in the chunk options. Have a read of http://yihui.name/knitr/options/#chunk_options as you may also want to use echo=FALSE to hide your code and/or message=FALSE to hide any messages that arise from loading packages.
E.g., if I don't specify message=FALSE I get:
Attaching package: ‘dplyr’
The following object is masked from ‘package:stats’:
filter
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
in the final output after loading dplyr.

how to use vision.ShapeInserter in matlab?

when I compile the command line, it is error. I do not know what is wrong? any any help. Thanks!
Create the shape inserter object.
shapeInserter = vision.ShapeInserter;
#%Read the input image.
I = imread('cameraman.tif');
#%Define the rectangle dimensions as [x y width height].
rectangle = int32([10 10 30 30]);
#%Draw the rectangle and display the result.
J = step(shapeInserter, I, rectangle);
imshow(J);
Error:
Undefined variable "vision" or function "vision.ShapeInserter".
Error in ve_hcn (line 3)
shapeInserter = vision.ShapeInserter;
ver :
MATLAB Version: 8.0.0.783 (R2012b)
MATLAB License Number: 724504
Operating System: Microsoft Windows 7 Version 6.2 (Build 9200)
Java Version: Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server >VM mixed mode
------------------------------------------------------------------------------------------------------- MATLAB Version 8.0
(R2012b) Communications System Toolbox Version
5.3 (R2012b) Control System Toolbox Version 9.4 (R2012b) DSP System Toolbox
Version 8.3 (R2012b) Image Processing Toolbox
Version 8.1 (R2012b) MATLAB Compiler
Version 4.18 (R2012b) MATLAB Report Generator
Version 3.13 (R2012b) Optimization Toolbox
Version 6.2.1 (R2012b) Parallel Computing Toolbox
Version 6.1 (R2012b) Partial Differential Equation Toolbox
Version 1.1 (R2012b) Signal Processing Toolbox
Version 6.18 (R2012b) Statistics Toolbox
Version 8.1 (R2012b) Symbolic Math Toolbox
Version 5.9 (R2012b)
vision.ShapeInserter is in the Computer Vision System Toolbox, which you don't seem to have installed. In the same toolbox (since release R2013a) there is also a function insertShape, which is easier to use.