Tag Archives: matlab
Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN
These data are already preprocessed so they are already syncronized and they are of the same size. However, when I tried running, MATLAB says: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN. What seems to be the problem with this and how can this be fixed?
% load data
clear;
clc;
ld1 = load(‘CALT23A.mat’);
ld2 = load(‘CALT23D.mat’);
ld3 = load(‘CALT23M.mat’);
ld4 = load(‘CALT23S.mat’);
ld5 = load(‘CALT23K.mat’);
%%
% Accelerometer
accx = mean([ld1.Acceleration.X ld2.Acceleration.X ld3.Acceleration.X ld4.Acceleration.X],2,’omitnan’);
accy = mean([ld1.Acceleration.Y ld2.Acceleration.Y ld3.Acceleration.Y ld4.Acceleration.Y],2,’omitnan’);
accz = mean([ld1.Acceleration.Z ld2.Acceleration.Z ld3.Acceleration.Z ld4.Acceleration.Z],2,’omitnan’);
accelerometerReadings = [accx accy accz];
% Gyroscope
angx = mean([ld1.AngularVelocity.X ld2.AngularVelocity.X ld3.AngularVelocity.X ld5.AngularVelocity.X],2,’omitnan’);
angy = mean([ld1.AngularVelocity.Y ld2.AngularVelocity.Y ld3.AngularVelocity.Y ld5.AngularVelocity.Y],2,’omitnan’);
angz = mean([ld1.AngularVelocity.Z ld2.AngularVelocity.Z ld3.AngularVelocity.Z ld5.AngularVelocity.Z],2,’omitnan’);
gyroscopeReadings = [angx angy angz];
% Magnetometer
magx = mean([ld1.MagneticField.X ld2.MagneticField.X ld3.MagneticField.X ld4.MagneticField.X],2,’omitnan’);
magy = mean([ld1.MagneticField.Y ld2.MagneticField.Y ld3.MagneticField.Y ld4.MagneticField.Y],2,’omitnan’);
magz = mean([ld1.MagneticField.Z ld2.MagneticField.Z ld3.MagneticField.Z ld4.MagneticField.Z],2,’omitnan’);
magnetometerReadings = [magx magy magz];
%GPS
lat = mean([ld1.Position.latitude ld2.Position.latitude ld3.Position.latitude ld4.Position.latitude],2,’omitnan’);
long = mean([ld1.Position.longitude ld2.Position.longitude ld3.Position.longitude ld4.Position.longitude],2,’omitnan’);
speed = mean([ld1.Position.speed ld2.Position.speed ld3.Position.speed ld4.Position.speed],2,’omitnan’);
gps_speed_combined = speed;
%% IMU Filter (indirect Kalman Filter)
fuse = imufilter(‘SampleRate’,100, ‘DecimationFactor’,1,’AccelerometerNoise’,0.5,’GyroscopeNoise’,0.01);
q1 = fuse(accelerometerReadings, gyroscopeReadings);
orient1 = eulerd(q1, ‘ZYX’,’frame’);
f = figure;
f.Position(1:4) = [100 20 1100 600];
plot(orient1(:,3)); hold off
grid on
axis tight
xlabel(‘Time (sec)’);
ylabel(‘Angle (deg)’);
title(‘Orientation Estimate using IMU Filter’)
saveas(gcf, ‘imufilter.png’)These data are already preprocessed so they are already syncronized and they are of the same size. However, when I tried running, MATLAB says: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN. What seems to be the problem with this and how can this be fixed?
% load data
clear;
clc;
ld1 = load(‘CALT23A.mat’);
ld2 = load(‘CALT23D.mat’);
ld3 = load(‘CALT23M.mat’);
ld4 = load(‘CALT23S.mat’);
ld5 = load(‘CALT23K.mat’);
%%
% Accelerometer
accx = mean([ld1.Acceleration.X ld2.Acceleration.X ld3.Acceleration.X ld4.Acceleration.X],2,’omitnan’);
accy = mean([ld1.Acceleration.Y ld2.Acceleration.Y ld3.Acceleration.Y ld4.Acceleration.Y],2,’omitnan’);
accz = mean([ld1.Acceleration.Z ld2.Acceleration.Z ld3.Acceleration.Z ld4.Acceleration.Z],2,’omitnan’);
accelerometerReadings = [accx accy accz];
% Gyroscope
angx = mean([ld1.AngularVelocity.X ld2.AngularVelocity.X ld3.AngularVelocity.X ld5.AngularVelocity.X],2,’omitnan’);
angy = mean([ld1.AngularVelocity.Y ld2.AngularVelocity.Y ld3.AngularVelocity.Y ld5.AngularVelocity.Y],2,’omitnan’);
angz = mean([ld1.AngularVelocity.Z ld2.AngularVelocity.Z ld3.AngularVelocity.Z ld5.AngularVelocity.Z],2,’omitnan’);
gyroscopeReadings = [angx angy angz];
% Magnetometer
magx = mean([ld1.MagneticField.X ld2.MagneticField.X ld3.MagneticField.X ld4.MagneticField.X],2,’omitnan’);
magy = mean([ld1.MagneticField.Y ld2.MagneticField.Y ld3.MagneticField.Y ld4.MagneticField.Y],2,’omitnan’);
magz = mean([ld1.MagneticField.Z ld2.MagneticField.Z ld3.MagneticField.Z ld4.MagneticField.Z],2,’omitnan’);
magnetometerReadings = [magx magy magz];
%GPS
lat = mean([ld1.Position.latitude ld2.Position.latitude ld3.Position.latitude ld4.Position.latitude],2,’omitnan’);
long = mean([ld1.Position.longitude ld2.Position.longitude ld3.Position.longitude ld4.Position.longitude],2,’omitnan’);
speed = mean([ld1.Position.speed ld2.Position.speed ld3.Position.speed ld4.Position.speed],2,’omitnan’);
gps_speed_combined = speed;
%% IMU Filter (indirect Kalman Filter)
fuse = imufilter(‘SampleRate’,100, ‘DecimationFactor’,1,’AccelerometerNoise’,0.5,’GyroscopeNoise’,0.01);
q1 = fuse(accelerometerReadings, gyroscopeReadings);
orient1 = eulerd(q1, ‘ZYX’,’frame’);
f = figure;
f.Position(1:4) = [100 20 1100 600];
plot(orient1(:,3)); hold off
grid on
axis tight
xlabel(‘Time (sec)’);
ylabel(‘Angle (deg)’);
title(‘Orientation Estimate using IMU Filter’)
saveas(gcf, ‘imufilter.png’) These data are already preprocessed so they are already syncronized and they are of the same size. However, when I tried running, MATLAB says: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN. What seems to be the problem with this and how can this be fixed?
% load data
clear;
clc;
ld1 = load(‘CALT23A.mat’);
ld2 = load(‘CALT23D.mat’);
ld3 = load(‘CALT23M.mat’);
ld4 = load(‘CALT23S.mat’);
ld5 = load(‘CALT23K.mat’);
%%
% Accelerometer
accx = mean([ld1.Acceleration.X ld2.Acceleration.X ld3.Acceleration.X ld4.Acceleration.X],2,’omitnan’);
accy = mean([ld1.Acceleration.Y ld2.Acceleration.Y ld3.Acceleration.Y ld4.Acceleration.Y],2,’omitnan’);
accz = mean([ld1.Acceleration.Z ld2.Acceleration.Z ld3.Acceleration.Z ld4.Acceleration.Z],2,’omitnan’);
accelerometerReadings = [accx accy accz];
% Gyroscope
angx = mean([ld1.AngularVelocity.X ld2.AngularVelocity.X ld3.AngularVelocity.X ld5.AngularVelocity.X],2,’omitnan’);
angy = mean([ld1.AngularVelocity.Y ld2.AngularVelocity.Y ld3.AngularVelocity.Y ld5.AngularVelocity.Y],2,’omitnan’);
angz = mean([ld1.AngularVelocity.Z ld2.AngularVelocity.Z ld3.AngularVelocity.Z ld5.AngularVelocity.Z],2,’omitnan’);
gyroscopeReadings = [angx angy angz];
% Magnetometer
magx = mean([ld1.MagneticField.X ld2.MagneticField.X ld3.MagneticField.X ld4.MagneticField.X],2,’omitnan’);
magy = mean([ld1.MagneticField.Y ld2.MagneticField.Y ld3.MagneticField.Y ld4.MagneticField.Y],2,’omitnan’);
magz = mean([ld1.MagneticField.Z ld2.MagneticField.Z ld3.MagneticField.Z ld4.MagneticField.Z],2,’omitnan’);
magnetometerReadings = [magx magy magz];
%GPS
lat = mean([ld1.Position.latitude ld2.Position.latitude ld3.Position.latitude ld4.Position.latitude],2,’omitnan’);
long = mean([ld1.Position.longitude ld2.Position.longitude ld3.Position.longitude ld4.Position.longitude],2,’omitnan’);
speed = mean([ld1.Position.speed ld2.Position.speed ld3.Position.speed ld4.Position.speed],2,’omitnan’);
gps_speed_combined = speed;
%% IMU Filter (indirect Kalman Filter)
fuse = imufilter(‘SampleRate’,100, ‘DecimationFactor’,1,’AccelerometerNoise’,0.5,’GyroscopeNoise’,0.01);
q1 = fuse(accelerometerReadings, gyroscopeReadings);
orient1 = eulerd(q1, ‘ZYX’,’frame’);
f = figure;
f.Position(1:4) = [100 20 1100 600];
plot(orient1(:,3)); hold off
grid on
axis tight
xlabel(‘Time (sec)’);
ylabel(‘Angle (deg)’);
title(‘Orientation Estimate using IMU Filter’)
saveas(gcf, ‘imufilter.png’) matrix, singular MATLAB Answers — New Questions
order using first column in array cell
newList=sortrows(newList,1);
Error using matlab.internal.math.cellstrpad
Cell elements must be character arrays.
Error in sortrows>sortBackToFrontCell (line 137)
tmp = matlab.internal.math.cellstrpad(A(I,ack));
Error in sortrows (line 77)
I = sortBackToFrontCell(A, col);newList=sortrows(newList,1);
Error using matlab.internal.math.cellstrpad
Cell elements must be character arrays.
Error in sortrows>sortBackToFrontCell (line 137)
tmp = matlab.internal.math.cellstrpad(A(I,ack));
Error in sortrows (line 77)
I = sortBackToFrontCell(A, col); newList=sortrows(newList,1);
Error using matlab.internal.math.cellstrpad
Cell elements must be character arrays.
Error in sortrows>sortBackToFrontCell (line 137)
tmp = matlab.internal.math.cellstrpad(A(I,ack));
Error in sortrows (line 77)
I = sortBackToFrontCell(A, col); order using first column in array cell MATLAB Answers — New Questions
How can I plot a spectrogram plotting time vs instantaneous frequency vs amplitude from an exported output signal?
I have a text file with time(1st column) and voltage amplitude (2nd column). How do I plot a spectrogram plotting time vs instantaneous frequency vs amplitude? Could you please help me plot it? I will really appreciate it.
I have attached the text file and a picture of the time domain representation of the signal.I have a text file with time(1st column) and voltage amplitude (2nd column). How do I plot a spectrogram plotting time vs instantaneous frequency vs amplitude? Could you please help me plot it? I will really appreciate it.
I have attached the text file and a picture of the time domain representation of the signal. I have a text file with time(1st column) and voltage amplitude (2nd column). How do I plot a spectrogram plotting time vs instantaneous frequency vs amplitude? Could you please help me plot it? I will really appreciate it.
I have attached the text file and a picture of the time domain representation of the signal. spectrogram, fft MATLAB Answers — New Questions
TS_PROCESS_CRASHED error virtualised macOS 14.4.1
Hello, I am trying to install MATLAB on a virtualised macOS 14.4.1 instance. However, the installer crashes, reporting ‘TS_PROCESS_CRASHED’. I have Corretto 11 installed and 12GB of RAM is allocated to the VM. What might be the cause of this? The host machine is a M3 Pro 36GB model.Hello, I am trying to install MATLAB on a virtualised macOS 14.4.1 instance. However, the installer crashes, reporting ‘TS_PROCESS_CRASHED’. I have Corretto 11 installed and 12GB of RAM is allocated to the VM. What might be the cause of this? The host machine is a M3 Pro 36GB model. Hello, I am trying to install MATLAB on a virtualised macOS 14.4.1 instance. However, the installer crashes, reporting ‘TS_PROCESS_CRASHED’. I have Corretto 11 installed and 12GB of RAM is allocated to the VM. What might be the cause of this? The host machine is a M3 Pro 36GB model. installation MATLAB Answers — New Questions
Creating sensor network on matlab
Dear Sir/Madam,
I just wanted to know how to create sensor network on matlab with different layers like physical,data link layer and network layer.Dear Sir/Madam,
I just wanted to know how to create sensor network on matlab with different layers like physical,data link layer and network layer. Dear Sir/Madam,
I just wanted to know how to create sensor network on matlab with different layers like physical,data link layer and network layer. sensor network MATLAB Answers — New Questions
The image errors when fitting MR damper data using bouc wen model
I’m trying to fit the MRD data using the Bouc Wen model, but there seems to be a problem with the image . I can’t find the cause of the problem.
the image just like thatI’m trying to fit the MRD data using the Bouc Wen model, but there seems to be a problem with the image . I can’t find the cause of the problem.
the image just like that I’m trying to fit the MRD data using the Bouc Wen model, but there seems to be a problem with the image . I can’t find the cause of the problem.
the image just like that bouc wen, mrdamper, matlab, curve fitting MATLAB Answers — New Questions
How to replace a dataset with different dimensions in an .H5 file – hdf5lib2 error
I have a dataset comprising a cube of images, with dimension 256x320x151. I need tu cut it down to a dataset with dimension 256x320x10, while keeping all the other attributes invariate, as they have useful information on the data acquisition parameters.
I have tried the code:
h5disp(‘PCA_cube – Copia.h5’)
fileattrib(‘PCA_cube – Copia.h5′,’+w’);
fid = H5F.open(‘PCA_cube – Copia.h5′,’H5F_ACC_RDWR’,’H5P_DEFAULT’);
dset_id = H5D.open(fid,’/Cube/Images’);
H5D.set_extent(dset_id,[320,256,10]); % C-style indexing
H5D.close(dset_id);
H5F.close(fid);
h5read(PCA_cube – Copia.h5′, ‘/Cube/Images’)
However I get the error message: "Error using hdf5lib2 : The HDF5 library encountered an error and produced the following stack trace information:H5D__set_extent dataset has contiguous storage"
I’m adding also some information on the file structure:
Any help or suggestion is much welcome!I have a dataset comprising a cube of images, with dimension 256x320x151. I need tu cut it down to a dataset with dimension 256x320x10, while keeping all the other attributes invariate, as they have useful information on the data acquisition parameters.
I have tried the code:
h5disp(‘PCA_cube – Copia.h5’)
fileattrib(‘PCA_cube – Copia.h5′,’+w’);
fid = H5F.open(‘PCA_cube – Copia.h5′,’H5F_ACC_RDWR’,’H5P_DEFAULT’);
dset_id = H5D.open(fid,’/Cube/Images’);
H5D.set_extent(dset_id,[320,256,10]); % C-style indexing
H5D.close(dset_id);
H5F.close(fid);
h5read(PCA_cube – Copia.h5′, ‘/Cube/Images’)
However I get the error message: "Error using hdf5lib2 : The HDF5 library encountered an error and produced the following stack trace information:H5D__set_extent dataset has contiguous storage"
I’m adding also some information on the file structure:
Any help or suggestion is much welcome! I have a dataset comprising a cube of images, with dimension 256x320x151. I need tu cut it down to a dataset with dimension 256x320x10, while keeping all the other attributes invariate, as they have useful information on the data acquisition parameters.
I have tried the code:
h5disp(‘PCA_cube – Copia.h5’)
fileattrib(‘PCA_cube – Copia.h5′,’+w’);
fid = H5F.open(‘PCA_cube – Copia.h5′,’H5F_ACC_RDWR’,’H5P_DEFAULT’);
dset_id = H5D.open(fid,’/Cube/Images’);
H5D.set_extent(dset_id,[320,256,10]); % C-style indexing
H5D.close(dset_id);
H5F.close(fid);
h5read(PCA_cube – Copia.h5′, ‘/Cube/Images’)
However I get the error message: "Error using hdf5lib2 : The HDF5 library encountered an error and produced the following stack trace information:H5D__set_extent dataset has contiguous storage"
I’m adding also some information on the file structure:
Any help or suggestion is much welcome! h5, hdf5lib2, dataset, hdf5 MATLAB Answers — New Questions
How can I calibrate a fixed camera to obtain accurate measurements of objects at different distances, despite height variations and pixel distortion?
I have a problem with calibration for detecting objects at different distances. I have a fixed camera, but the objects are not stationary. The issue is that when I perform the calibration using a scale to detect objects with real measurements, if the height changes, I get different results due to pixel variation. My question is how can I calculate the measurements of any object at varying distances to obtain accurate real-world results?"I have a problem with calibration for detecting objects at different distances. I have a fixed camera, but the objects are not stationary. The issue is that when I perform the calibration using a scale to detect objects with real measurements, if the height changes, I get different results due to pixel variation. My question is how can I calculate the measurements of any object at varying distances to obtain accurate real-world results?" I have a problem with calibration for detecting objects at different distances. I have a fixed camera, but the objects are not stationary. The issue is that when I perform the calibration using a scale to detect objects with real measurements, if the height changes, I get different results due to pixel variation. My question is how can I calculate the measurements of any object at varying distances to obtain accurate real-world results?" calibration, image, camera MATLAB Answers — New Questions
Why is detectImportOptions not sheet agnostic with a named Range?
I can use the following line
opts = detectImportOptions(workbookFile,’Sheet’,sheetName,’Range’,Range);
containing an excel range name (see name manager) in Range and the corresponding sheet name in sheetName. The thing is, excel already allows me to set range names for the whole workbook. So, no need to specify the sheet name. I’d like my script to be agnostic to changes in sheet names or positions.
How can I do that?
If I launch without sheetName
opts = detectImportOptions(workbookFile,’Range’,Range);
Matlab doesn’t find my range, although the range name in excel is given with "Scope: Workbook".I can use the following line
opts = detectImportOptions(workbookFile,’Sheet’,sheetName,’Range’,Range);
containing an excel range name (see name manager) in Range and the corresponding sheet name in sheetName. The thing is, excel already allows me to set range names for the whole workbook. So, no need to specify the sheet name. I’d like my script to be agnostic to changes in sheet names or positions.
How can I do that?
If I launch without sheetName
opts = detectImportOptions(workbookFile,’Range’,Range);
Matlab doesn’t find my range, although the range name in excel is given with "Scope: Workbook". I can use the following line
opts = detectImportOptions(workbookFile,’Sheet’,sheetName,’Range’,Range);
containing an excel range name (see name manager) in Range and the corresponding sheet name in sheetName. The thing is, excel already allows me to set range names for the whole workbook. So, no need to specify the sheet name. I’d like my script to be agnostic to changes in sheet names or positions.
How can I do that?
If I launch without sheetName
opts = detectImportOptions(workbookFile,’Range’,Range);
Matlab doesn’t find my range, although the range name in excel is given with "Scope: Workbook". excel MATLAB Answers — New Questions
add cell to arraycell
i want to add sistema to oldList but i reveive error
newList=[{sistema} oldList];
Error using horzcat
Dimensions of arrays being concatenated are not consistent.i want to add sistema to oldList but i reveive error
newList=[{sistema} oldList];
Error using horzcat
Dimensions of arrays being concatenated are not consistent. i want to add sistema to oldList but i reveive error
newList=[{sistema} oldList];
Error using horzcat
Dimensions of arrays being concatenated are not consistent. add cell to arraycell MATLAB Answers — New Questions
filling Index issues imfindcircles
Im having issue where i think the index is looking for instances of detected circles but it either is not filling the index or maybe there isnt enough to fill the array but im having issue getting this to work. its from the help documentation so i expected it to just work but im still having trouble and thus am having trouble understanding how to use imfindcircles. I tried using edge(canny) and using a binary image to see if that would make it easier to find circles but im still hvaing issues.
A = imread(‘coins.png’);
imshow(A)
[centers, radii, metric] = imfindcircles(A,[15 30]);
centersStrong5 = centers(1:5,:);
radiiStrong5 = radii(1:5);
metricStrong5 = metric(1:5);
viscircles(centersStrong5, radiiStrong5,’EdgeColor’,’b’);Im having issue where i think the index is looking for instances of detected circles but it either is not filling the index or maybe there isnt enough to fill the array but im having issue getting this to work. its from the help documentation so i expected it to just work but im still having trouble and thus am having trouble understanding how to use imfindcircles. I tried using edge(canny) and using a binary image to see if that would make it easier to find circles but im still hvaing issues.
A = imread(‘coins.png’);
imshow(A)
[centers, radii, metric] = imfindcircles(A,[15 30]);
centersStrong5 = centers(1:5,:);
radiiStrong5 = radii(1:5);
metricStrong5 = metric(1:5);
viscircles(centersStrong5, radiiStrong5,’EdgeColor’,’b’); Im having issue where i think the index is looking for instances of detected circles but it either is not filling the index or maybe there isnt enough to fill the array but im having issue getting this to work. its from the help documentation so i expected it to just work but im still having trouble and thus am having trouble understanding how to use imfindcircles. I tried using edge(canny) and using a binary image to see if that would make it easier to find circles but im still hvaing issues.
A = imread(‘coins.png’);
imshow(A)
[centers, radii, metric] = imfindcircles(A,[15 30]);
centersStrong5 = centers(1:5,:);
radiiStrong5 = radii(1:5);
metricStrong5 = metric(1:5);
viscircles(centersStrong5, radiiStrong5,’EdgeColor’,’b’); imfindcircles, matlab, hough transform, edge detection, image processing toolbox MATLAB Answers — New Questions
How to maximize achievable Rate for spectrum sharing in MIMO?
Hello, I am simulating a paper. I want to maximize achievable rate but there is an error in my code. the problem is maximiz (sum(log(1 + p2_k/ (sigma^2 + norm(w2_k,2)^2)))) when P2 and W2 are my variable matrices subject to 0=< p2_k =< tilde_P2 and sum( p2_k * xi_k =< zeta1_l. I used CVX function for optimization but I am not sure if it is true or not. my error is "Disciplined convex programming error:
Cannot perform the operation: {real affine} ./ {convex}" .
I would really appreciate it if someone could help me with it.
thank you in advance.Hello, I am simulating a paper. I want to maximize achievable rate but there is an error in my code. the problem is maximiz (sum(log(1 + p2_k/ (sigma^2 + norm(w2_k,2)^2)))) when P2 and W2 are my variable matrices subject to 0=< p2_k =< tilde_P2 and sum( p2_k * xi_k =< zeta1_l. I used CVX function for optimization but I am not sure if it is true or not. my error is "Disciplined convex programming error:
Cannot perform the operation: {real affine} ./ {convex}" .
I would really appreciate it if someone could help me with it.
thank you in advance. Hello, I am simulating a paper. I want to maximize achievable rate but there is an error in my code. the problem is maximiz (sum(log(1 + p2_k/ (sigma^2 + norm(w2_k,2)^2)))) when P2 and W2 are my variable matrices subject to 0=< p2_k =< tilde_P2 and sum( p2_k * xi_k =< zeta1_l. I used CVX function for optimization but I am not sure if it is true or not. my error is "Disciplined convex programming error:
Cannot perform the operation: {real affine} ./ {convex}" .
I would really appreciate it if someone could help me with it.
thank you in advance. achievable rate, spectrum sharing, matlab, for loop MATLAB Answers — New Questions
Error with addpoints when trying to animate a trajectory following a marker
I am trying to animate a trajectory following a marker.
Here is the problematic part of my code:
figure(1)
axis([0, ceil(max(x)), 0, ceil(max(y))])
daspect([1 1 1])
grid on
xlabel(‘x (m)’), ylabel(‘y (m)’), title(‘Bouncing Projectile’), subtitle([‘{theta} = ‘, num2str(theta), ‘°, u = ‘, num2str(u), ‘ ms^{-1}, h = ‘, num2str(h), ‘ m, g = ‘, num2str(g), ‘ ms^{-2}, C = ‘, num2str(C), ‘, N = ‘, num2str(N)])
h = animatedline(‘Color’, ‘b’);
p = plot(x(1), y(1), ‘o’, ‘MarkerEdgeColor’, ‘red’, ‘MarkerFaceColor’, ‘red’);
for k = 1:length(x)
p.XData = x(k);
p.YData = y(k);
addpoints(h, x(k), y(k));
drawnow limitrate
pause(dt)
end
Whithout the code for the marker, the program runs well. However, for some strange reason, adding the code for the marker seems to create an error:
Error using matlab.graphics.animation.AnimatedLine/addpoints
Value must be a handle.
Error in file (line 54)
addpoints(h, x(k), y(k));
A graph is produced when I run the program, however the axes are not labeled, there is no title, and only one point is plotted.
What mistake have I made?I am trying to animate a trajectory following a marker.
Here is the problematic part of my code:
figure(1)
axis([0, ceil(max(x)), 0, ceil(max(y))])
daspect([1 1 1])
grid on
xlabel(‘x (m)’), ylabel(‘y (m)’), title(‘Bouncing Projectile’), subtitle([‘{theta} = ‘, num2str(theta), ‘°, u = ‘, num2str(u), ‘ ms^{-1}, h = ‘, num2str(h), ‘ m, g = ‘, num2str(g), ‘ ms^{-2}, C = ‘, num2str(C), ‘, N = ‘, num2str(N)])
h = animatedline(‘Color’, ‘b’);
p = plot(x(1), y(1), ‘o’, ‘MarkerEdgeColor’, ‘red’, ‘MarkerFaceColor’, ‘red’);
for k = 1:length(x)
p.XData = x(k);
p.YData = y(k);
addpoints(h, x(k), y(k));
drawnow limitrate
pause(dt)
end
Whithout the code for the marker, the program runs well. However, for some strange reason, adding the code for the marker seems to create an error:
Error using matlab.graphics.animation.AnimatedLine/addpoints
Value must be a handle.
Error in file (line 54)
addpoints(h, x(k), y(k));
A graph is produced when I run the program, however the axes are not labeled, there is no title, and only one point is plotted.
What mistake have I made? I am trying to animate a trajectory following a marker.
Here is the problematic part of my code:
figure(1)
axis([0, ceil(max(x)), 0, ceil(max(y))])
daspect([1 1 1])
grid on
xlabel(‘x (m)’), ylabel(‘y (m)’), title(‘Bouncing Projectile’), subtitle([‘{theta} = ‘, num2str(theta), ‘°, u = ‘, num2str(u), ‘ ms^{-1}, h = ‘, num2str(h), ‘ m, g = ‘, num2str(g), ‘ ms^{-2}, C = ‘, num2str(C), ‘, N = ‘, num2str(N)])
h = animatedline(‘Color’, ‘b’);
p = plot(x(1), y(1), ‘o’, ‘MarkerEdgeColor’, ‘red’, ‘MarkerFaceColor’, ‘red’);
for k = 1:length(x)
p.XData = x(k);
p.YData = y(k);
addpoints(h, x(k), y(k));
drawnow limitrate
pause(dt)
end
Whithout the code for the marker, the program runs well. However, for some strange reason, adding the code for the marker seems to create an error:
Error using matlab.graphics.animation.AnimatedLine/addpoints
Value must be a handle.
Error in file (line 54)
addpoints(h, x(k), y(k));
A graph is produced when I run the program, however the axes are not labeled, there is no title, and only one point is plotted.
What mistake have I made? matlab MATLAB Answers — New Questions
what does the MATLAB function ‘helperMIMOChannelEstimate’ estimates
Does the function helperMIMOChannelEstimate estimates and returns perfect channel estimate or is it using any basic channel estimation algorithm like LS OR MMMSE to calculate it.Does the function helperMIMOChannelEstimate estimates and returns perfect channel estimate or is it using any basic channel estimation algorithm like LS OR MMMSE to calculate it. Does the function helperMIMOChannelEstimate estimates and returns perfect channel estimate or is it using any basic channel estimation algorithm like LS OR MMMSE to calculate it. helpermimochannelestimate, least squares, mmse MATLAB Answers — New Questions
Mathworks account login problems, anonymous user
My Mathworks account seems to be corrupted or hacked.
At the time of login, i could see the initials of another anonymous person for brief time.
Later it shows my account initals, VB
The number of answers, count is also showing incorrectly. it has not changed since 2 3 weeks. despite answering enough questions.
Anyone has idea how to solve this problem.My Mathworks account seems to be corrupted or hacked.
At the time of login, i could see the initials of another anonymous person for brief time.
Later it shows my account initals, VB
The number of answers, count is also showing incorrectly. it has not changed since 2 3 weeks. despite answering enough questions.
Anyone has idea how to solve this problem. My Mathworks account seems to be corrupted or hacked.
At the time of login, i could see the initials of another anonymous person for brief time.
Later it shows my account initals, VB
The number of answers, count is also showing incorrectly. it has not changed since 2 3 weeks. despite answering enough questions.
Anyone has idea how to solve this problem. mathworks account, answers, count, login MATLAB Answers — New Questions
While loading an object of class ‘nnet.cnn.TrainingOptionsSGDM’: The value of ‘ValidationData’ is invalid. Unable to read file: ‘D:#KAHSYAPFYPTransferLearningtrainingdata
Post Content Post Content validation data, unable to read file MATLAB Answers — New Questions
How to create http MessageBody body with fields that contain dashes
I would like to create http message bodies with fields that contain dashes. I haven’t been able to find a workaround for Matlab disallowing hyphens (dashes) in the var names.
Here is what I’m trying to do – for illustration – I have an underscore in place of a hyphen the "test_var" (below)
Even after generating the RequestMessage (req1 below), you cannot change "test_var" to "test-var" because the RequestMessage is still storing the request as a struct (not as a string which could be modified).
method = matlab.net.http.RequestMethod.POST;
header = matlab.net.http.HeaderField(‘Content-Type’, ‘application/json’);
header = addFields(header,’User-Agent’, ‘my-client/99.9’);
header = addFields(header,’Accept’, ‘application/json’);
% Struct approach
struct1 = struct(‘login’, ‘me’, ‘password’, ‘pw123’, ‘test_var’, true)
body1 = matlab.net.http.MessageBody(struct1)
req1 = matlab.net.http.RequestMessage(method,header,body1)
show(req1)
POST
Content-Type: application/json
User-Agent: my-client/99.9
Accept: application/json
{"login":"me","password":"pw123","test_var":true}
req1.Body.Data
ans =
struct with fields:
login: ‘me’
password: ‘pw123’
test_var: 1I would like to create http message bodies with fields that contain dashes. I haven’t been able to find a workaround for Matlab disallowing hyphens (dashes) in the var names.
Here is what I’m trying to do – for illustration – I have an underscore in place of a hyphen the "test_var" (below)
Even after generating the RequestMessage (req1 below), you cannot change "test_var" to "test-var" because the RequestMessage is still storing the request as a struct (not as a string which could be modified).
method = matlab.net.http.RequestMethod.POST;
header = matlab.net.http.HeaderField(‘Content-Type’, ‘application/json’);
header = addFields(header,’User-Agent’, ‘my-client/99.9’);
header = addFields(header,’Accept’, ‘application/json’);
% Struct approach
struct1 = struct(‘login’, ‘me’, ‘password’, ‘pw123’, ‘test_var’, true)
body1 = matlab.net.http.MessageBody(struct1)
req1 = matlab.net.http.RequestMessage(method,header,body1)
show(req1)
POST
Content-Type: application/json
User-Agent: my-client/99.9
Accept: application/json
{"login":"me","password":"pw123","test_var":true}
req1.Body.Data
ans =
struct with fields:
login: ‘me’
password: ‘pw123’
test_var: 1 I would like to create http message bodies with fields that contain dashes. I haven’t been able to find a workaround for Matlab disallowing hyphens (dashes) in the var names.
Here is what I’m trying to do – for illustration – I have an underscore in place of a hyphen the "test_var" (below)
Even after generating the RequestMessage (req1 below), you cannot change "test_var" to "test-var" because the RequestMessage is still storing the request as a struct (not as a string which could be modified).
method = matlab.net.http.RequestMethod.POST;
header = matlab.net.http.HeaderField(‘Content-Type’, ‘application/json’);
header = addFields(header,’User-Agent’, ‘my-client/99.9’);
header = addFields(header,’Accept’, ‘application/json’);
% Struct approach
struct1 = struct(‘login’, ‘me’, ‘password’, ‘pw123’, ‘test_var’, true)
body1 = matlab.net.http.MessageBody(struct1)
req1 = matlab.net.http.RequestMessage(method,header,body1)
show(req1)
POST
Content-Type: application/json
User-Agent: my-client/99.9
Accept: application/json
{"login":"me","password":"pw123","test_var":true}
req1.Body.Data
ans =
struct with fields:
login: ‘me’
password: ‘pw123’
test_var: 1 #messagebody, #requestmessage MATLAB Answers — New Questions
A numerical calculation problem leading to Inf or NaN in matlab
I want to calculate the exact value of , where and is a very large positive number. Obviously, we have the bound ,and therefore .
However, in reality, for example, if , due to the large , we have and the matlab will treat it as 0 and .
On the other hand, if , due to the large , we have a very large and matlab will treat the sum as Inf and . So how to avoid the above two cases and get the exact value of F in matlab?I want to calculate the exact value of , where and is a very large positive number. Obviously, we have the bound ,and therefore .
However, in reality, for example, if , due to the large , we have and the matlab will treat it as 0 and .
On the other hand, if , due to the large , we have a very large and matlab will treat the sum as Inf and . So how to avoid the above two cases and get the exact value of F in matlab? I want to calculate the exact value of , where and is a very large positive number. Obviously, we have the bound ,and therefore .
However, in reality, for example, if , due to the large , we have and the matlab will treat it as 0 and .
On the other hand, if , due to the large , we have a very large and matlab will treat the sum as Inf and . So how to avoid the above two cases and get the exact value of F in matlab? numerical calculation, nan MATLAB Answers — New Questions
How to reach train and test and their predictions in nftool?
I have conducted neural network on my dataset with 228 rows and 7 columns but don’t know how to obtain my training and testing datasets and their prediction values. I want to export this values.
% Solve an Input-Output Fitting problem with a Neural Network
% Script generated by Neural Fitting app
% Created 20-Jul-2024 16:31:01
%
% This script assumes these variables are defined:
%
% data – input data.
% data_1 – target data.
x = data’;
t = data_1′;
% Choose a Training Function
% For a list of all training functions type: help nntrain
% ‘trainlm’ is usually fastest.
% ‘trainbr’ takes longer but may be better for challenging problems.
% ‘trainscg’ uses less memory. Suitable in low memory situations.
trainFcn = ‘trainlm’; % Levenberg-Marquardt backpropagation.
% Create a Fitting Network
hiddenLayerSize = 4;
net = fitnet(hiddenLayerSize,trainFcn);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train the Network
[net,tr] = train(net,x,t);
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
% View the Network
view(net)
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotfit(net,x,t)I have conducted neural network on my dataset with 228 rows and 7 columns but don’t know how to obtain my training and testing datasets and their prediction values. I want to export this values.
% Solve an Input-Output Fitting problem with a Neural Network
% Script generated by Neural Fitting app
% Created 20-Jul-2024 16:31:01
%
% This script assumes these variables are defined:
%
% data – input data.
% data_1 – target data.
x = data’;
t = data_1′;
% Choose a Training Function
% For a list of all training functions type: help nntrain
% ‘trainlm’ is usually fastest.
% ‘trainbr’ takes longer but may be better for challenging problems.
% ‘trainscg’ uses less memory. Suitable in low memory situations.
trainFcn = ‘trainlm’; % Levenberg-Marquardt backpropagation.
% Create a Fitting Network
hiddenLayerSize = 4;
net = fitnet(hiddenLayerSize,trainFcn);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train the Network
[net,tr] = train(net,x,t);
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
% View the Network
view(net)
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotfit(net,x,t) I have conducted neural network on my dataset with 228 rows and 7 columns but don’t know how to obtain my training and testing datasets and their prediction values. I want to export this values.
% Solve an Input-Output Fitting problem with a Neural Network
% Script generated by Neural Fitting app
% Created 20-Jul-2024 16:31:01
%
% This script assumes these variables are defined:
%
% data – input data.
% data_1 – target data.
x = data’;
t = data_1′;
% Choose a Training Function
% For a list of all training functions type: help nntrain
% ‘trainlm’ is usually fastest.
% ‘trainbr’ takes longer but may be better for challenging problems.
% ‘trainscg’ uses less memory. Suitable in low memory situations.
trainFcn = ‘trainlm’; % Levenberg-Marquardt backpropagation.
% Create a Fitting Network
hiddenLayerSize = 4;
net = fitnet(hiddenLayerSize,trainFcn);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train the Network
[net,tr] = train(net,x,t);
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
% View the Network
view(net)
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotregression(t,y)
%figure, plotfit(net,x,t) nftool, train, test, predictions, export results MATLAB Answers — New Questions
How can I remove a line off UIAxes on App designer in RealTime with SpeedGoat
Hi,
Im creating an app using App designer and Simulink in Realtime with a speedgoat. I have a drop down menu that has a selection of position or velocity. Depending on what is selected I want to plot it on a UIaxes. However, for instance, when I go from velocity to poisition or vice versa, The graph keeps both lines on the UIAxes. I only need to show one line that corresponds to the value of the dropdown list. Im using connectline() command to plot. I tried using clearScalarAndLineData() command to clear the axes but it is not working. My issue is that I cannot get rid of a line once I use the connectline() command. I also tried using cla() but once I use it, it will not replot during the simulation.
My desire is to have when the dropdown list equals to position, the UIaxes will plot only the position signal and when the dropdown list equals velocity, it will only plot the velocity signal during simulation.
Here is my code so far
function PlotSelectValueChanged(app, event)
value = app.PlotSelect.Value;
if value == "Position"
app.Instrument = slrealtime.Instrument(app.SLRTApp);
addInstrumentedSignals(app.Instrument)
app.Instrument.connectLine(app.DataPlotAxes,"Pos_AX1");
app.Instrument.AxesTimeSpan = 10;
app.Instrument.AxesTimeSpanOverrun = ‘wrap’;
app.InstrumentManager = slrealtime.ui.tool.InstrumentManager(app.BenchTopUIFigure, ‘TargetSource’, app.TargetSelector);
app.InstrumentManager.Instruments = app.Instrument;
elseif value == "velocity"
app.Instrument = slrealtime.Instrument(app.SLRTApp);
addInstrumentedSignals(app.Instrument)
app.Instrument.connectLine(app.DataPlotAxes,"Vel_AX1");
app.Instrument.AxesTimeSpan = 10;
app.Instrument.AxesTimeSpanOverrun = ‘wrap’;
app.InstrumentManager = slrealtime.ui.tool.InstrumentManager(app.BenchTopUIFigure, ‘TargetSource’, app.TargetSelector);
app.InstrumentManager.Instruments = app.Instrument;
end
end
ThanksHi,
Im creating an app using App designer and Simulink in Realtime with a speedgoat. I have a drop down menu that has a selection of position or velocity. Depending on what is selected I want to plot it on a UIaxes. However, for instance, when I go from velocity to poisition or vice versa, The graph keeps both lines on the UIAxes. I only need to show one line that corresponds to the value of the dropdown list. Im using connectline() command to plot. I tried using clearScalarAndLineData() command to clear the axes but it is not working. My issue is that I cannot get rid of a line once I use the connectline() command. I also tried using cla() but once I use it, it will not replot during the simulation.
My desire is to have when the dropdown list equals to position, the UIaxes will plot only the position signal and when the dropdown list equals velocity, it will only plot the velocity signal during simulation.
Here is my code so far
function PlotSelectValueChanged(app, event)
value = app.PlotSelect.Value;
if value == "Position"
app.Instrument = slrealtime.Instrument(app.SLRTApp);
addInstrumentedSignals(app.Instrument)
app.Instrument.connectLine(app.DataPlotAxes,"Pos_AX1");
app.Instrument.AxesTimeSpan = 10;
app.Instrument.AxesTimeSpanOverrun = ‘wrap’;
app.InstrumentManager = slrealtime.ui.tool.InstrumentManager(app.BenchTopUIFigure, ‘TargetSource’, app.TargetSelector);
app.InstrumentManager.Instruments = app.Instrument;
elseif value == "velocity"
app.Instrument = slrealtime.Instrument(app.SLRTApp);
addInstrumentedSignals(app.Instrument)
app.Instrument.connectLine(app.DataPlotAxes,"Vel_AX1");
app.Instrument.AxesTimeSpan = 10;
app.Instrument.AxesTimeSpanOverrun = ‘wrap’;
app.InstrumentManager = slrealtime.ui.tool.InstrumentManager(app.BenchTopUIFigure, ‘TargetSource’, app.TargetSelector);
app.InstrumentManager.Instruments = app.Instrument;
end
end
Thanks Hi,
Im creating an app using App designer and Simulink in Realtime with a speedgoat. I have a drop down menu that has a selection of position or velocity. Depending on what is selected I want to plot it on a UIaxes. However, for instance, when I go from velocity to poisition or vice versa, The graph keeps both lines on the UIAxes. I only need to show one line that corresponds to the value of the dropdown list. Im using connectline() command to plot. I tried using clearScalarAndLineData() command to clear the axes but it is not working. My issue is that I cannot get rid of a line once I use the connectline() command. I also tried using cla() but once I use it, it will not replot during the simulation.
My desire is to have when the dropdown list equals to position, the UIaxes will plot only the position signal and when the dropdown list equals velocity, it will only plot the velocity signal during simulation.
Here is my code so far
function PlotSelectValueChanged(app, event)
value = app.PlotSelect.Value;
if value == "Position"
app.Instrument = slrealtime.Instrument(app.SLRTApp);
addInstrumentedSignals(app.Instrument)
app.Instrument.connectLine(app.DataPlotAxes,"Pos_AX1");
app.Instrument.AxesTimeSpan = 10;
app.Instrument.AxesTimeSpanOverrun = ‘wrap’;
app.InstrumentManager = slrealtime.ui.tool.InstrumentManager(app.BenchTopUIFigure, ‘TargetSource’, app.TargetSelector);
app.InstrumentManager.Instruments = app.Instrument;
elseif value == "velocity"
app.Instrument = slrealtime.Instrument(app.SLRTApp);
addInstrumentedSignals(app.Instrument)
app.Instrument.connectLine(app.DataPlotAxes,"Vel_AX1");
app.Instrument.AxesTimeSpan = 10;
app.Instrument.AxesTimeSpanOverrun = ‘wrap’;
app.InstrumentManager = slrealtime.ui.tool.InstrumentManager(app.BenchTopUIFigure, ‘TargetSource’, app.TargetSelector);
app.InstrumentManager.Instruments = app.Instrument;
end
end
Thanks simulink, appdesigner MATLAB Answers — New Questions