Tag Archives: matlab
Remote access to a Simulink Real-Time Speedgoat target through VPN
https://www.mathworks.com/matlabcentral/answers/2039236-how-can-i-access-a-simulink-real-time-slrt-speedgoat-target-computer-on-a-separate-network Are there any guidelines for remotely accessing a Simulink Real-Time (SLRT) Speedgoat target computer through VPN?https://www.mathworks.com/matlabcentral/answers/2039236-how-can-i-access-a-simulink-real-time-slrt-speedgoat-target-computer-on-a-separate-network Are there any guidelines for remotely accessing a Simulink Real-Time (SLRT) Speedgoat target computer through VPN? https://www.mathworks.com/matlabcentral/answers/2039236-how-can-i-access-a-simulink-real-time-slrt-speedgoat-target-computer-on-a-separate-network Are there any guidelines for remotely accessing a Simulink Real-Time (SLRT) Speedgoat target computer through VPN? slrt, speedgoat, remote, access, vpn MATLAB Answers — New Questions
Easy way of finding zero crossing of a function
I am trying to find zero-crossings of a function in Matlab and plot the points where zero-crossing occurs. However, i am not able to find an easy way. I tried <http://terpconnect.umd.edu/~toh/spectrum/PeakFindingandMeasurement.htm>
and Matlab fnzeros, but i can’t understand the spmak and x,y used in these function.
The function for which i want to find zero crossing is Euclidean distance function. I will really appreciate if someone can tell me an easy way of doing this.I am trying to find zero-crossings of a function in Matlab and plot the points where zero-crossing occurs. However, i am not able to find an easy way. I tried <http://terpconnect.umd.edu/~toh/spectrum/PeakFindingandMeasurement.htm>
and Matlab fnzeros, but i can’t understand the spmak and x,y used in these function.
The function for which i want to find zero crossing is Euclidean distance function. I will really appreciate if someone can tell me an easy way of doing this. I am trying to find zero-crossings of a function in Matlab and plot the points where zero-crossing occurs. However, i am not able to find an easy way. I tried <http://terpconnect.umd.edu/~toh/spectrum/PeakFindingandMeasurement.htm>
and Matlab fnzeros, but i can’t understand the spmak and x,y used in these function.
The function for which i want to find zero crossing is Euclidean distance function. I will really appreciate if someone can tell me an easy way of doing this. image processing, digital image processing, image analysis MATLAB Answers — New Questions
Why is there no effect of flipping the normals using poisson in pc2surfacemesh?
I am using following code to reconstruct a surface with poisson using pc2surfacemesh. I have reconstructed the surface twice, once with normal looking into the inside of the model. The second time mirrored so pointing outwards. There was no difference between the two mesh. I don’t know where to look at the code to determine the reconstruction. My question is does the function correct the normal when calculating.
ptcloud = pcread(‘Auto_Filter_35.ply’);
pcshow(ptcloud)
% flip normals
ptcloud.Normal = -ptcloud.Normal;
% Subsampling of ptCloud because of runtime
gridstep = 0.007;
ptCloudDownSampled = pcdownsample(ptcloud,"gridAverage",gridstep);
%% Construct surface mesh from the point cloud data using the Poisson method, and display the surface mesh.
tic
depth = 12;
mesh = pc2surfacemesh(ptCloudDownSampled,"poisson",depth);
surfaceMeshShow(mesh)
toc
writeSurfaceMesh(mesh,"AutoMesh35_flipedNormal.ply")I am using following code to reconstruct a surface with poisson using pc2surfacemesh. I have reconstructed the surface twice, once with normal looking into the inside of the model. The second time mirrored so pointing outwards. There was no difference between the two mesh. I don’t know where to look at the code to determine the reconstruction. My question is does the function correct the normal when calculating.
ptcloud = pcread(‘Auto_Filter_35.ply’);
pcshow(ptcloud)
% flip normals
ptcloud.Normal = -ptcloud.Normal;
% Subsampling of ptCloud because of runtime
gridstep = 0.007;
ptCloudDownSampled = pcdownsample(ptcloud,"gridAverage",gridstep);
%% Construct surface mesh from the point cloud data using the Poisson method, and display the surface mesh.
tic
depth = 12;
mesh = pc2surfacemesh(ptCloudDownSampled,"poisson",depth);
surfaceMeshShow(mesh)
toc
writeSurfaceMesh(mesh,"AutoMesh35_flipedNormal.ply") I am using following code to reconstruct a surface with poisson using pc2surfacemesh. I have reconstructed the surface twice, once with normal looking into the inside of the model. The second time mirrored so pointing outwards. There was no difference between the two mesh. I don’t know where to look at the code to determine the reconstruction. My question is does the function correct the normal when calculating.
ptcloud = pcread(‘Auto_Filter_35.ply’);
pcshow(ptcloud)
% flip normals
ptcloud.Normal = -ptcloud.Normal;
% Subsampling of ptCloud because of runtime
gridstep = 0.007;
ptCloudDownSampled = pcdownsample(ptcloud,"gridAverage",gridstep);
%% Construct surface mesh from the point cloud data using the Poisson method, and display the surface mesh.
tic
depth = 12;
mesh = pc2surfacemesh(ptCloudDownSampled,"poisson",depth);
surfaceMeshShow(mesh)
toc
writeSurfaceMesh(mesh,"AutoMesh35_flipedNormal.ply") surface, poisson, reconstruction, 3d MATLAB Answers — New Questions
detecting (unwanted) pixels and removing them
Hi everyone,
Based on this image,
<</matlabcentral/answers/uploaded_files/105368/Brain_img_unwrapped.png>>
I want to detect some pixels that have larger value than other pixels and delete them, basically the ones you see at the boundary of the mask as well as the flow artifacts in the image itself.
Any help is highly appreciated!
CheersHi everyone,
Based on this image,
<</matlabcentral/answers/uploaded_files/105368/Brain_img_unwrapped.png>>
I want to detect some pixels that have larger value than other pixels and delete them, basically the ones you see at the boundary of the mask as well as the flow artifacts in the image itself.
Any help is highly appreciated!
Cheers Hi everyone,
Based on this image,
<</matlabcentral/answers/uploaded_files/105368/Brain_img_unwrapped.png>>
I want to detect some pixels that have larger value than other pixels and delete them, basically the ones you see at the boundary of the mask as well as the flow artifacts in the image itself.
Any help is highly appreciated!
Cheers mri, algorithm, phase, unwrapping, phase unwraping, image processing MATLAB Answers — New Questions
Is there a way to stop compiling process when the model has started to compile in Simulink?
I am running Simulink with Raspberry Pi and when I had hit RUN button, I realized that the model had some errors, but couldn’t find any option to TERMINATE THE COMPILATION PROCESS
Either I’d have to wait 20 minutes for the compilation process to complete or restart MATLAB.
I had to chose the 2nd one.I am running Simulink with Raspberry Pi and when I had hit RUN button, I realized that the model had some errors, but couldn’t find any option to TERMINATE THE COMPILATION PROCESS
Either I’d have to wait 20 minutes for the compilation process to complete or restart MATLAB.
I had to chose the 2nd one. I am running Simulink with Raspberry Pi and when I had hit RUN button, I realized that the model had some errors, but couldn’t find any option to TERMINATE THE COMPILATION PROCESS
Either I’d have to wait 20 minutes for the compilation process to complete or restart MATLAB.
I had to chose the 2nd one. simulink, model, compiler, raspberry pi MATLAB Answers — New Questions
The format of data for a deep learning model CAE.
I’m looking to create a deep learning CAE model. Inside the "trainnet" folder are JPEG files that I intend to use as input and output images for training the model. How should I format these images to trainnet for learning? For example, please explain the format and method for data within "trainnet(X)". Thank you.I’m looking to create a deep learning CAE model. Inside the "trainnet" folder are JPEG files that I intend to use as input and output images for training the model. How should I format these images to trainnet for learning? For example, please explain the format and method for data within "trainnet(X)". Thank you. I’m looking to create a deep learning CAE model. Inside the "trainnet" folder are JPEG files that I intend to use as input and output images for training the model. How should I format these images to trainnet for learning? For example, please explain the format and method for data within "trainnet(X)". Thank you. deep learning, cae, data structure MATLAB Answers — New Questions
How to set radii in imfindingcircles function?
dear all, i’m trying to create a mask for this image based on the fuction imfindingcircles. I tried setting different thresholds but I didn’t get the rigth result. Can anybody help me? than I would like to set NaN to the mask. Thank you in advance!
clear all
close all
clc
A= imread(‘image_1567.png’);
[rows, columns, numberOfColorChannels] = size(A)
%imshow(A)
[centers,radii] = imfindcircles(A,[50 100],Sensitivity=0.9);
mask = circles2mask(centers,radii,size(A));
figure
montage({A,mask})
A(~(A == mask)) = nandear all, i’m trying to create a mask for this image based on the fuction imfindingcircles. I tried setting different thresholds but I didn’t get the rigth result. Can anybody help me? than I would like to set NaN to the mask. Thank you in advance!
clear all
close all
clc
A= imread(‘image_1567.png’);
[rows, columns, numberOfColorChannels] = size(A)
%imshow(A)
[centers,radii] = imfindcircles(A,[50 100],Sensitivity=0.9);
mask = circles2mask(centers,radii,size(A));
figure
montage({A,mask})
A(~(A == mask)) = nan dear all, i’m trying to create a mask for this image based on the fuction imfindingcircles. I tried setting different thresholds but I didn’t get the rigth result. Can anybody help me? than I would like to set NaN to the mask. Thank you in advance!
clear all
close all
clc
A= imread(‘image_1567.png’);
[rows, columns, numberOfColorChannels] = size(A)
%imshow(A)
[centers,radii] = imfindcircles(A,[50 100],Sensitivity=0.9);
mask = circles2mask(centers,radii,size(A));
figure
montage({A,mask})
A(~(A == mask)) = nan imfindcircles, mask, image processing, image segmentation MATLAB Answers — New Questions
Problem of rotation of surface on xy plane
Hi everyone,
I am using this code on this point cloud imported in XYZ format, in which I would like to calculate the difference between the maximum and minimum points in the profile. To do this, the cloud must be rotated on the XY plane (see output figure). However, it seems to have an incorrect rotation. Can someone help me fix the rotation?
Thank you very much
clear all
close all
clc
load(‘xyz_c1p1’);
X = xyz_c1p1(:,1);
Y = xyz_c1p1(:,2);
Z = xyz_c1p1(:,3);
xyz0=mean(xyz_c1p1,1);
A=xyz_c1p1-xyz0; % center the data at zero
% Find the direction of most variance using SVD and rotate the data to make
% that the x-axis
[~,~,V]=svd(A,0);
a=cross(V(:,3),[0;0;1]);
T=makehgtform(‘axisrotate’, a, -atan2(norm(a),V(3,3)));;
R=T(1:3,1:3);
A_rot = A*R;
A_rot = A_rot + [xyz0(1) xyz0(2) 0]; % move so the centers are aligned in z-diection
% Plot the raw data
close all
scatter3(X,Y,Z,0.1,"magenta")
hold on
scatter3(A_rot(:,1),A_rot(:,2),A_rot(:,3),0.1,’blue’);
xlabel(‘X-Axis’,’FontSize’,14,’FontWeight’,’bold’)
ylabel(‘Y-Axis’,’FontSize’,14,’FontWeight’,’bold’)
zlabel(‘Z-Axis’,’FontSize’,14,’FontWeight’,’bold’)
axis equal
Zmax = max(A_rot(:,3))
Zmin = min(A_rot(:,3))
Rz = Zmax – Zmin
hold on
% Alpha Shape
shpINT=alphaShape(A_rot,5);
figure(3)
plot(shpINT)
VolAlphaShapeINT=volume(shpINT);Hi everyone,
I am using this code on this point cloud imported in XYZ format, in which I would like to calculate the difference between the maximum and minimum points in the profile. To do this, the cloud must be rotated on the XY plane (see output figure). However, it seems to have an incorrect rotation. Can someone help me fix the rotation?
Thank you very much
clear all
close all
clc
load(‘xyz_c1p1’);
X = xyz_c1p1(:,1);
Y = xyz_c1p1(:,2);
Z = xyz_c1p1(:,3);
xyz0=mean(xyz_c1p1,1);
A=xyz_c1p1-xyz0; % center the data at zero
% Find the direction of most variance using SVD and rotate the data to make
% that the x-axis
[~,~,V]=svd(A,0);
a=cross(V(:,3),[0;0;1]);
T=makehgtform(‘axisrotate’, a, -atan2(norm(a),V(3,3)));;
R=T(1:3,1:3);
A_rot = A*R;
A_rot = A_rot + [xyz0(1) xyz0(2) 0]; % move so the centers are aligned in z-diection
% Plot the raw data
close all
scatter3(X,Y,Z,0.1,"magenta")
hold on
scatter3(A_rot(:,1),A_rot(:,2),A_rot(:,3),0.1,’blue’);
xlabel(‘X-Axis’,’FontSize’,14,’FontWeight’,’bold’)
ylabel(‘Y-Axis’,’FontSize’,14,’FontWeight’,’bold’)
zlabel(‘Z-Axis’,’FontSize’,14,’FontWeight’,’bold’)
axis equal
Zmax = max(A_rot(:,3))
Zmin = min(A_rot(:,3))
Rz = Zmax – Zmin
hold on
% Alpha Shape
shpINT=alphaShape(A_rot,5);
figure(3)
plot(shpINT)
VolAlphaShapeINT=volume(shpINT); Hi everyone,
I am using this code on this point cloud imported in XYZ format, in which I would like to calculate the difference between the maximum and minimum points in the profile. To do this, the cloud must be rotated on the XY plane (see output figure). However, it seems to have an incorrect rotation. Can someone help me fix the rotation?
Thank you very much
clear all
close all
clc
load(‘xyz_c1p1’);
X = xyz_c1p1(:,1);
Y = xyz_c1p1(:,2);
Z = xyz_c1p1(:,3);
xyz0=mean(xyz_c1p1,1);
A=xyz_c1p1-xyz0; % center the data at zero
% Find the direction of most variance using SVD and rotate the data to make
% that the x-axis
[~,~,V]=svd(A,0);
a=cross(V(:,3),[0;0;1]);
T=makehgtform(‘axisrotate’, a, -atan2(norm(a),V(3,3)));;
R=T(1:3,1:3);
A_rot = A*R;
A_rot = A_rot + [xyz0(1) xyz0(2) 0]; % move so the centers are aligned in z-diection
% Plot the raw data
close all
scatter3(X,Y,Z,0.1,"magenta")
hold on
scatter3(A_rot(:,1),A_rot(:,2),A_rot(:,3),0.1,’blue’);
xlabel(‘X-Axis’,’FontSize’,14,’FontWeight’,’bold’)
ylabel(‘Y-Axis’,’FontSize’,14,’FontWeight’,’bold’)
zlabel(‘Z-Axis’,’FontSize’,14,’FontWeight’,’bold’)
axis equal
Zmax = max(A_rot(:,3))
Zmin = min(A_rot(:,3))
Rz = Zmax – Zmin
hold on
% Alpha Shape
shpINT=alphaShape(A_rot,5);
figure(3)
plot(shpINT)
VolAlphaShapeINT=volume(shpINT); rotation, axis rotation, xyz file MATLAB Answers — New Questions
Error using contourf Z must be at least a 2×2 matrix. Error in D18071 (line 106) contourf(st)
Hi, I am trying to create contour plot but after trying many times I am getting the same error, can anyone tell me what I am doing wrong in the code
*The code is*
s su = round(4*d/g)+1 ;
r = E((((su-1)- round(d/g)):-1:1),(su-1));
p = E((((su-1)- round(d/g)):-1:1),(su));
st = (p+r)./(1.5*(10)^(-4));
m = g*(size(r)-1);
H = 0:g:(m);
h = H./10;
writematrix(st)
type ‘st.txt’
writematrix(h)
type ‘h.txt’
plot(h,st)
xlim([0 1.5])
xlabel("X2/d",’fontsize’,14)
ylabel("Normalised Strain along vertical path", ‘fontsize’,13)
legend("d/w = 0.5")
saveas(gcf,’plot.png’)
contourf(st)
colorbar
saveas(gcf,’contour.png’)Hi, I am trying to create contour plot but after trying many times I am getting the same error, can anyone tell me what I am doing wrong in the code
*The code is*
s su = round(4*d/g)+1 ;
r = E((((su-1)- round(d/g)):-1:1),(su-1));
p = E((((su-1)- round(d/g)):-1:1),(su));
st = (p+r)./(1.5*(10)^(-4));
m = g*(size(r)-1);
H = 0:g:(m);
h = H./10;
writematrix(st)
type ‘st.txt’
writematrix(h)
type ‘h.txt’
plot(h,st)
xlim([0 1.5])
xlabel("X2/d",’fontsize’,14)
ylabel("Normalised Strain along vertical path", ‘fontsize’,13)
legend("d/w = 0.5")
saveas(gcf,’plot.png’)
contourf(st)
colorbar
saveas(gcf,’contour.png’) Hi, I am trying to create contour plot but after trying many times I am getting the same error, can anyone tell me what I am doing wrong in the code
*The code is*
s su = round(4*d/g)+1 ;
r = E((((su-1)- round(d/g)):-1:1),(su-1));
p = E((((su-1)- round(d/g)):-1:1),(su));
st = (p+r)./(1.5*(10)^(-4));
m = g*(size(r)-1);
H = 0:g:(m);
h = H./10;
writematrix(st)
type ‘st.txt’
writematrix(h)
type ‘h.txt’
plot(h,st)
xlim([0 1.5])
xlabel("X2/d",’fontsize’,14)
ylabel("Normalised Strain along vertical path", ‘fontsize’,13)
legend("d/w = 0.5")
saveas(gcf,’plot.png’)
contourf(st)
colorbar
saveas(gcf,’contour.png’) abaqus MATLAB Answers — New Questions
How to get r-square,mean absolute error and mean square error after train neural network?
Hi all, I train neural network as follow command
net.divideFcn = ‘dividerand’
net.divideParam.trainRatio= 0.6;
net.divideParam.testRatio= 0.2;
net.divideParam.valRatio= 0.2;
[net,tr]=train(net,input,target);
I want to get r-square,mean absolute error and mean square error from train,test and validation data
Cloud you please advice ?Hi all, I train neural network as follow command
net.divideFcn = ‘dividerand’
net.divideParam.trainRatio= 0.6;
net.divideParam.testRatio= 0.2;
net.divideParam.valRatio= 0.2;
[net,tr]=train(net,input,target);
I want to get r-square,mean absolute error and mean square error from train,test and validation data
Cloud you please advice ? Hi all, I train neural network as follow command
net.divideFcn = ‘dividerand’
net.divideParam.trainRatio= 0.6;
net.divideParam.testRatio= 0.2;
net.divideParam.valRatio= 0.2;
[net,tr]=train(net,input,target);
I want to get r-square,mean absolute error and mean square error from train,test and validation data
Cloud you please advice ? neural network, matlab MATLAB Answers — New Questions
Unit Step Function and Sinusoidal Input
For the given system with transfer function
G(S) = 10 / (S2 + 2S + 20)
If G(S) = Y(S) / X(S), where Y(S) is the output and X(S) is the input. Compute for the output if the input is a. unit step function and b. sinusoidal input. Then simulate using MATLAB and compare the result. Plot the response of the system. Compare the result of the two different inputs.For the given system with transfer function
G(S) = 10 / (S2 + 2S + 20)
If G(S) = Y(S) / X(S), where Y(S) is the output and X(S) is the input. Compute for the output if the input is a. unit step function and b. sinusoidal input. Then simulate using MATLAB and compare the result. Plot the response of the system. Compare the result of the two different inputs. For the given system with transfer function
G(S) = 10 / (S2 + 2S + 20)
If G(S) = Y(S) / X(S), where Y(S) is the output and X(S) is the input. Compute for the output if the input is a. unit step function and b. sinusoidal input. Then simulate using MATLAB and compare the result. Plot the response of the system. Compare the result of the two different inputs. transfer function MATLAB Answers — New Questions
Don’t know why it is showing incorrect?
I get an incorrect mark in the task(2) of 13.2 section of Matlab onramp course.Even if i saw the solution in the see solution option and entered the same the error still shows.
the task is given below:
Modify the script so that when the if condition is not satisfied, the following line of code is executed:
disp("The density of " + element …
+ " is " + density)I get an incorrect mark in the task(2) of 13.2 section of Matlab onramp course.Even if i saw the solution in the see solution option and entered the same the error still shows.
the task is given below:
Modify the script so that when the if condition is not satisfied, the following line of code is executed:
disp("The density of " + element …
+ " is " + density) I get an incorrect mark in the task(2) of 13.2 section of Matlab onramp course.Even if i saw the solution in the see solution option and entered the same the error still shows.
the task is given below:
Modify the script so that when the if condition is not satisfied, the following line of code is executed:
disp("The density of " + element …
+ " is " + density) error, matlab, onramp, training, online_training MATLAB Answers — New Questions
Conditional Compilation Of Simulink Model Code Generation
hi, as following picture shows, when after generate code, during compile how to control just let fun2 code enter compile process, fun1 code is forbidden to enter compile.hi, as following picture shows, when after generate code, during compile how to control just let fun2 code enter compile process, fun1 code is forbidden to enter compile. hi, as following picture shows, when after generate code, during compile how to control just let fun2 code enter compile process, fun1 code is forbidden to enter compile. simulink, embedded coder, conditional compilation MATLAB Answers — New Questions
Is MATLAB affected by the Homeland Security Vulnerability Notice regarding Java?
On January 10, 2013, the United States Computer Emergency Readiness team issued a Vulnerability Notice for the Oracle Java Runtime Environment: http://www.kb.cert.org/vuls/id/625617.
This notice recommends that Java be disabled in web browsers.On January 10, 2013, the United States Computer Emergency Readiness team issued a Vulnerability Notice for the Oracle Java Runtime Environment: http://www.kb.cert.org/vuls/id/625617.
This notice recommends that Java be disabled in web browsers. On January 10, 2013, the United States Computer Emergency Readiness team issued a Vulnerability Notice for the Oracle Java Runtime Environment: http://www.kb.cert.org/vuls/id/625617.
This notice recommends that Java be disabled in web browsers. MATLAB Answers — New Questions
Why does my stand-alone created using the MATLAB Compiler take longer to start the first time?
It takes longer to start my stand-alone application the first time it is run than consecutive runs. Also if I run the application some time later, it again takes longer the first time but becomes faster on consecutive runs. I would expect it to always start quicker after the first run.It takes longer to start my stand-alone application the first time it is run than consecutive runs. Also if I run the application some time later, it again takes longer the first time but becomes faster on consecutive runs. I would expect it to always start quicker after the first run. It takes longer to start my stand-alone application the first time it is run than consecutive runs. Also if I run the application some time later, it again takes longer the first time but becomes faster on consecutive runs. I would expect it to always start quicker after the first run. standalone, mcr, slow, slower, fast, faster, second MATLAB Answers — New Questions
Why does MATLAB place the file msdia80.dll in the root of the boot drive for Windows x64?
After installing MATLAB on a 64 bit Windows machine, there is msdia80.dll on the root of the boot drive (C:). Prior to installation that file was not there. Why is the file in the root and how can I move it?After installing MATLAB on a 64 bit Windows machine, there is msdia80.dll on the root of the boot drive (C:). Prior to installation that file was not there. Why is the file in the root and how can I move it? After installing MATLAB on a 64 bit Windows machine, there is msdia80.dll on the root of the boot drive (C:). Prior to installation that file was not there. Why is the file in the root and how can I move it? MATLAB Answers — New Questions
The custom loss function, which is trained with the dlarray structure, reports an error when using sgdmupdate to update, and cannot be assigned, because this type of variable
% 定义 LSTM 网络结构
numFeatures = size(X_train, 2); % 特征数量,这里是 3
numHiddenUnits = 100; % LSTM 隐藏单元数量
layers = [ …
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits)
fullyConnectedLayer(numFeatures)
];
maxEpochs = 50;
miniBatchSize = 3;
learningRate = 0.01;
% 初始化 LSTM 模型
net = dlnetwork(layers); % 在 CPU 上训练
% 训练循环
numObservations = size(X_train, 1);
numMiniBatches = floor(numObservations / miniBatchSize);
averageGrad = [];
averageSqGrad = [];
iteration = 0;
Velocities = zeros(size(net));
momentum = 0.9;
for epoch = 1:maxEpochs
% 打乱训练数据
idx = randperm(numObservations);
X_train_shuffled = X_train(idx, :);
Y_train_shuffled = Y_train(idx, :);
totalLoss = 0;
for i = 1:numMiniBatches
idxBatch = (i – 1) * miniBatchSize + 1 : i * miniBatchSize;
X_batch = X_train_shuffled(idxBatch, :);
Y_batch = Y_train_shuffled(idxBatch, :);
iteration = iteration + 1;
% 前向传播计算预测
Y_pred = predict(net, X_batch’);
Y_pred = Y_pred’;
Y_pred = dlarray(Y_pred, ‘TS’);
Y_batch = dlarray(Y_batch, ‘TS’);
%loss = mean(( Y_batch – Y_pred).^2, ‘all’);
[loss_1, gradients] = dlfeval(@customLoss, Y_batch, Y_pred);
gradients = extractdata(gradients);
[net, Velocities] = sgdmupdate(net, gradients, Velocities,learningRate,momentum);
% 计算损失
% loss = customLoss(Y_batch, Y_pred);
% totalLoss = totalLoss + loss;
% 反向传播更新梯度
%dL_dY = 2 * (Y_pred – Y_batch) / miniBatchSize;
%gradients = dlgradient(loss, net.LearnableParameters);
%net = updateParameters(net, gradients, learningRate);
end
% 显示每个 epoch 的平均损失
avgLoss = totalLoss / numMiniBatches;
fprintf(‘Epoch %d, Average Loss: %.4fn’, epoch, avgLoss);
end
无法执行赋值,因为此类型的变量不支持使用点进行索引。
出错 deep.internal.recording.containerfeval>iProcessNetwork_Nout_Nin (第 382 行)
protoTable.Value = zeros(height(protoTable),0);
出错 deep.internal.recording.containerfeval>iDispatch_Nout_Nin (第 214 行)
outputs = iProcessNetwork_Nout_Nin(fun, paramFun, numOut, …
出错 deep.internal.recording.containerfeval (第 38 行)
outputs = iDispatch_Nout_Nin(allowNetInput, fun, paramFun, numOut, …
出错 deep.internal.networkContainerFixedArgsFun (第 29 行)
varargout = deep.internal.recording.containerfeval(…
出错 sgdmupdate (第 126 行)
[p, vel] = deep.internal.networkContainerFixedArgsFun(func, …% 定义 LSTM 网络结构
numFeatures = size(X_train, 2); % 特征数量,这里是 3
numHiddenUnits = 100; % LSTM 隐藏单元数量
layers = [ …
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits)
fullyConnectedLayer(numFeatures)
];
maxEpochs = 50;
miniBatchSize = 3;
learningRate = 0.01;
% 初始化 LSTM 模型
net = dlnetwork(layers); % 在 CPU 上训练
% 训练循环
numObservations = size(X_train, 1);
numMiniBatches = floor(numObservations / miniBatchSize);
averageGrad = [];
averageSqGrad = [];
iteration = 0;
Velocities = zeros(size(net));
momentum = 0.9;
for epoch = 1:maxEpochs
% 打乱训练数据
idx = randperm(numObservations);
X_train_shuffled = X_train(idx, :);
Y_train_shuffled = Y_train(idx, :);
totalLoss = 0;
for i = 1:numMiniBatches
idxBatch = (i – 1) * miniBatchSize + 1 : i * miniBatchSize;
X_batch = X_train_shuffled(idxBatch, :);
Y_batch = Y_train_shuffled(idxBatch, :);
iteration = iteration + 1;
% 前向传播计算预测
Y_pred = predict(net, X_batch’);
Y_pred = Y_pred’;
Y_pred = dlarray(Y_pred, ‘TS’);
Y_batch = dlarray(Y_batch, ‘TS’);
%loss = mean(( Y_batch – Y_pred).^2, ‘all’);
[loss_1, gradients] = dlfeval(@customLoss, Y_batch, Y_pred);
gradients = extractdata(gradients);
[net, Velocities] = sgdmupdate(net, gradients, Velocities,learningRate,momentum);
% 计算损失
% loss = customLoss(Y_batch, Y_pred);
% totalLoss = totalLoss + loss;
% 反向传播更新梯度
%dL_dY = 2 * (Y_pred – Y_batch) / miniBatchSize;
%gradients = dlgradient(loss, net.LearnableParameters);
%net = updateParameters(net, gradients, learningRate);
end
% 显示每个 epoch 的平均损失
avgLoss = totalLoss / numMiniBatches;
fprintf(‘Epoch %d, Average Loss: %.4fn’, epoch, avgLoss);
end
无法执行赋值,因为此类型的变量不支持使用点进行索引。
出错 deep.internal.recording.containerfeval>iProcessNetwork_Nout_Nin (第 382 行)
protoTable.Value = zeros(height(protoTable),0);
出错 deep.internal.recording.containerfeval>iDispatch_Nout_Nin (第 214 行)
outputs = iProcessNetwork_Nout_Nin(fun, paramFun, numOut, …
出错 deep.internal.recording.containerfeval (第 38 行)
outputs = iDispatch_Nout_Nin(allowNetInput, fun, paramFun, numOut, …
出错 deep.internal.networkContainerFixedArgsFun (第 29 行)
varargout = deep.internal.recording.containerfeval(…
出错 sgdmupdate (第 126 行)
[p, vel] = deep.internal.networkContainerFixedArgsFun(func, … % 定义 LSTM 网络结构
numFeatures = size(X_train, 2); % 特征数量,这里是 3
numHiddenUnits = 100; % LSTM 隐藏单元数量
layers = [ …
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits)
fullyConnectedLayer(numFeatures)
];
maxEpochs = 50;
miniBatchSize = 3;
learningRate = 0.01;
% 初始化 LSTM 模型
net = dlnetwork(layers); % 在 CPU 上训练
% 训练循环
numObservations = size(X_train, 1);
numMiniBatches = floor(numObservations / miniBatchSize);
averageGrad = [];
averageSqGrad = [];
iteration = 0;
Velocities = zeros(size(net));
momentum = 0.9;
for epoch = 1:maxEpochs
% 打乱训练数据
idx = randperm(numObservations);
X_train_shuffled = X_train(idx, :);
Y_train_shuffled = Y_train(idx, :);
totalLoss = 0;
for i = 1:numMiniBatches
idxBatch = (i – 1) * miniBatchSize + 1 : i * miniBatchSize;
X_batch = X_train_shuffled(idxBatch, :);
Y_batch = Y_train_shuffled(idxBatch, :);
iteration = iteration + 1;
% 前向传播计算预测
Y_pred = predict(net, X_batch’);
Y_pred = Y_pred’;
Y_pred = dlarray(Y_pred, ‘TS’);
Y_batch = dlarray(Y_batch, ‘TS’);
%loss = mean(( Y_batch – Y_pred).^2, ‘all’);
[loss_1, gradients] = dlfeval(@customLoss, Y_batch, Y_pred);
gradients = extractdata(gradients);
[net, Velocities] = sgdmupdate(net, gradients, Velocities,learningRate,momentum);
% 计算损失
% loss = customLoss(Y_batch, Y_pred);
% totalLoss = totalLoss + loss;
% 反向传播更新梯度
%dL_dY = 2 * (Y_pred – Y_batch) / miniBatchSize;
%gradients = dlgradient(loss, net.LearnableParameters);
%net = updateParameters(net, gradients, learningRate);
end
% 显示每个 epoch 的平均损失
avgLoss = totalLoss / numMiniBatches;
fprintf(‘Epoch %d, Average Loss: %.4fn’, epoch, avgLoss);
end
无法执行赋值,因为此类型的变量不支持使用点进行索引。
出错 deep.internal.recording.containerfeval>iProcessNetwork_Nout_Nin (第 382 行)
protoTable.Value = zeros(height(protoTable),0);
出错 deep.internal.recording.containerfeval>iDispatch_Nout_Nin (第 214 行)
outputs = iProcessNetwork_Nout_Nin(fun, paramFun, numOut, …
出错 deep.internal.recording.containerfeval (第 38 行)
outputs = iDispatch_Nout_Nin(allowNetInput, fun, paramFun, numOut, …
出错 deep.internal.networkContainerFixedArgsFun (第 29 行)
varargout = deep.internal.recording.containerfeval(…
出错 sgdmupdate (第 126 行)
[p, vel] = deep.internal.networkContainerFixedArgsFun(func, … sgdmupdate, deeplearning, lstm, dlarray MATLAB Answers — New Questions
Why do I experience performance issues with the License Center?
When I try to load the license center it takes a long time to let me in or list licenses. Additionally, when I choose a license, it can take a long time to process and let me work with it.When I try to load the license center it takes a long time to let me in or list licenses. Additionally, when I choose a license, it can take a long time to process and let me work with it. When I try to load the license center it takes a long time to let me in or list licenses. Additionally, when I choose a license, it can take a long time to process and let me work with it. MATLAB Answers — New Questions
Something doesn’t work for me in fit
Hello friends.
A little introduction:
I do a simulation for particles moving inside a box, as part of the simulation I measure the speed of the particles, and the idea is that in the end I get the Maxwell-Boltzmann distribution of the speed.
I wanted to do a fit to the histogram of the velocity, according to the Boltzmann equation, so that I could find the temperature of the system, but for some reason the fit does not fit exactly on the data. it’s similar, but not enough.
this is the fit that I get:
I’m uploading code with the histogram data, so you can run it yourself and see what you get.
I only change the histogram() in the figure, to plot(), so that it matches the data I uploaded.
This is the equation of Boltzmann distribution that I want to fit:
I will be happy if you can understand what is the problems..thanks!
This is the code, you can simple run it and see what is happening:
%my data:
hist_x=[10 30 50 70 90 110 130 150 170 190 210 230 250,…
270 290 310 330 350 370 390 410 430 450 470 490];
hist_y=[20 60 83 88 108 117 113 94 77 63 65 51 26,…
19 9 3 1 2 0 0 0 0 0 0 1];
%fit the velocity to Boltzmann distribution:
%parameters:
K_B=1.38e-23; %[m^2Kg/s^2K]
m=39.948*1.660e-27 ; %mass of Ar, convert from atomic mass to Kg [Kg]
boltzmann = fittype…
( @(T,v) (m/K_B*T)*v.*exp(((-m)/(2*K_B*T))*v.^2)…
, ‘coefficient’, ‘T’…
, ‘independent’, ‘v’) ;
[fitted_curve] = fit(hist_x’,hist_y’,boltzmann, ‘startPoint’, 100) ;
%plot histogram and fit:
figure;
plot(hist_x,hist_y);
hold on
plot(fitted_curve)
title(‘histogram of velocity and fitted curve – Boltzmann distribution’)
legend(‘histogram’, ‘fitted curve’);
xlabel(‘velovity [m/s]’)
ylabel(‘particles amount’)
disp(fitted_curve);Hello friends.
A little introduction:
I do a simulation for particles moving inside a box, as part of the simulation I measure the speed of the particles, and the idea is that in the end I get the Maxwell-Boltzmann distribution of the speed.
I wanted to do a fit to the histogram of the velocity, according to the Boltzmann equation, so that I could find the temperature of the system, but for some reason the fit does not fit exactly on the data. it’s similar, but not enough.
this is the fit that I get:
I’m uploading code with the histogram data, so you can run it yourself and see what you get.
I only change the histogram() in the figure, to plot(), so that it matches the data I uploaded.
This is the equation of Boltzmann distribution that I want to fit:
I will be happy if you can understand what is the problems..thanks!
This is the code, you can simple run it and see what is happening:
%my data:
hist_x=[10 30 50 70 90 110 130 150 170 190 210 230 250,…
270 290 310 330 350 370 390 410 430 450 470 490];
hist_y=[20 60 83 88 108 117 113 94 77 63 65 51 26,…
19 9 3 1 2 0 0 0 0 0 0 1];
%fit the velocity to Boltzmann distribution:
%parameters:
K_B=1.38e-23; %[m^2Kg/s^2K]
m=39.948*1.660e-27 ; %mass of Ar, convert from atomic mass to Kg [Kg]
boltzmann = fittype…
( @(T,v) (m/K_B*T)*v.*exp(((-m)/(2*K_B*T))*v.^2)…
, ‘coefficient’, ‘T’…
, ‘independent’, ‘v’) ;
[fitted_curve] = fit(hist_x’,hist_y’,boltzmann, ‘startPoint’, 100) ;
%plot histogram and fit:
figure;
plot(hist_x,hist_y);
hold on
plot(fitted_curve)
title(‘histogram of velocity and fitted curve – Boltzmann distribution’)
legend(‘histogram’, ‘fitted curve’);
xlabel(‘velovity [m/s]’)
ylabel(‘particles amount’)
disp(fitted_curve); Hello friends.
A little introduction:
I do a simulation for particles moving inside a box, as part of the simulation I measure the speed of the particles, and the idea is that in the end I get the Maxwell-Boltzmann distribution of the speed.
I wanted to do a fit to the histogram of the velocity, according to the Boltzmann equation, so that I could find the temperature of the system, but for some reason the fit does not fit exactly on the data. it’s similar, but not enough.
this is the fit that I get:
I’m uploading code with the histogram data, so you can run it yourself and see what you get.
I only change the histogram() in the figure, to plot(), so that it matches the data I uploaded.
This is the equation of Boltzmann distribution that I want to fit:
I will be happy if you can understand what is the problems..thanks!
This is the code, you can simple run it and see what is happening:
%my data:
hist_x=[10 30 50 70 90 110 130 150 170 190 210 230 250,…
270 290 310 330 350 370 390 410 430 450 470 490];
hist_y=[20 60 83 88 108 117 113 94 77 63 65 51 26,…
19 9 3 1 2 0 0 0 0 0 0 1];
%fit the velocity to Boltzmann distribution:
%parameters:
K_B=1.38e-23; %[m^2Kg/s^2K]
m=39.948*1.660e-27 ; %mass of Ar, convert from atomic mass to Kg [Kg]
boltzmann = fittype…
( @(T,v) (m/K_B*T)*v.*exp(((-m)/(2*K_B*T))*v.^2)…
, ‘coefficient’, ‘T’…
, ‘independent’, ‘v’) ;
[fitted_curve] = fit(hist_x’,hist_y’,boltzmann, ‘startPoint’, 100) ;
%plot histogram and fit:
figure;
plot(hist_x,hist_y);
hold on
plot(fitted_curve)
title(‘histogram of velocity and fitted curve – Boltzmann distribution’)
legend(‘histogram’, ‘fitted curve’);
xlabel(‘velovity [m/s]’)
ylabel(‘particles amount’)
disp(fitted_curve); curve fitting MATLAB Answers — New Questions
Getting an exception at the Power_usage.Rice_Cooker(Tstart) = 0; line
% Import data into a table
rice_cooker = [0.0000 0.0000 0.0000 0.0000 0.0863 0.5180 0.4317 0.0432 0.0863 0.0000 0.0000 0.0432 0.1295 0.1295 0.0000 0.0000 0.0000 0.0863 0.4748 0.3885 0.0432 0.0000 0.0000 0.0000]’;
blender = [0.0000 0.0000 0.0000 0.0000 0.0207 0.1861 0.1861 0.0207 0.0207 0.0000 0.0207 0.0207 0.0207 0.0000 0.0000 0.0414 0.0414 0.0414 0.1034 0.0620 0.0000 0.0000 0.0000 0.0000
]’;
hour = (1:24)’;
Starting_Probability = table(hour, rice_cooker, blender);
Starting_Probability.Properties.VariableNames{‘rice_cooker’} = ‘Rice_Cooker’;
Starting_Probability.Properties.VariableNames{‘blender’} = ‘Blender’;
% Import data into another table
cycle_t_first_column = [0 0 0 0 41 32 31 30 0 0 30 30 15 40 0 0 0 20 35 29 45 0 0 0
]’;
cycle_t_second_column = [0 0 0 0 10 8 7 9 15 0 13 18 21 10 15 0 9 11 8 7 10 0 0 0
]’;
cycle_t = table(cycle_t_first_column,cycle_t_second_column);
cycle_t.Properties.VariableNames{‘cycle_t_first_column’} = ‘Rice_Cooker’;
cycle_t.Properties.VariableNames{‘cycle_t_second_column’} = ‘Blender’;
% Import data into another table
app_pwr_first_column = [0.000 0.000 0.000 0.000 1.525 1.271 1.220 0.700 0.000 0.000 1.400 1.550 1.000 1.333 0.000 0.000 0.000 1.300 1.600 1.260 1.500 0.000 0.000 0.000
]’;
app_pwr_second_column = [0.000 0.000 0.000 0.000 0.550 0.543 0.682 0.325 0.978 0.000 0.328 0.365 0.525 0.775 0.374 0.000 0.138 0.494 0.567 0.507 2.000 0.000 0.000 0.000
]’;
app_pwr = table(app_pwr_first_column,app_pwr_second_column);
app_pwr.Properties.VariableNames{‘app_pwr_first_column’} = ‘Rice_Cooker’;
app_pwr.Properties.VariableNames{‘app_pwr_second_column’} = ‘Blender’;
app_pwr.Properties.RowNames = cellstr(num2str((1:24)’));
% Create a table named Power_usage with two columns and 24 rows
Power_usage = table(zeros(24,1), zeros(24,1));
% Rename the columns as RiceCooker and Blender
Power_usage.Properties.VariableNames = {‘Rice_Cooker’, ‘Blender’};
% Rename the rows as 1 to 24
Power_usage.Properties.RowNames = cellstr(num2str((1:24)’));
% Get the values of Tstart and Applno variables
Tstart = 2; %input(‘Enter the value of Tstart: ‘);
Applno = 1; %input(‘Enter the value of Applno: ‘);
%% Create a loop until Tstart equals 24
while Tstart <= 24
% Generate 100 random numbers between 0 and 1
x = rand(100,1);
% Assign the 100th random number to a variable named r
r = x(100);
% Check the random number against the element of T table
if Applno == 1 % RiceCooker column
if r < Starting_Probability.Rice_Cooker(Tstart) % Random number is greater than element value
% Read the value from app_pwr table and store it in Power_usage table
Power_usage.Rice_Cooker(Tstart) = app_pwr.Rice_Cooker(Tstart);
else % Random number is less than element value
% Store 0 in Power_usage table
Power_usage.Rice_Cooker(Tstart) = 0;
end
elseif Applno == 2 % Blender column
if r < Starting_Probability.Blender(Tstart) % Random number is greater than element value
% Read the value from app_pwr table and store it in Power_usage table
Power_usage.Blender(Tstart) = app_pwr.Blender(Tstart);
else % Random number is less than element value
% Store 0 in Power_usage table
Power_usage.Blender(Tstart) = 0;
end
end
% Get the value of Tcycle from cycle_t table
if Applno == 1 % RiceCooker column
Tcycle = cycle_t.Rice_Cooker(Tstart);
elseif Applno == 2 % Blender column
Tcycle = cycle_t.Blender(Tstart);
end
% Update Tstart as per the equation
Tstart = Tstart + Tcycle;
end
% I’m getting an error at the Power_usage.Rice_Cooker(Tstart) = 0; line% Import data into a table
rice_cooker = [0.0000 0.0000 0.0000 0.0000 0.0863 0.5180 0.4317 0.0432 0.0863 0.0000 0.0000 0.0432 0.1295 0.1295 0.0000 0.0000 0.0000 0.0863 0.4748 0.3885 0.0432 0.0000 0.0000 0.0000]’;
blender = [0.0000 0.0000 0.0000 0.0000 0.0207 0.1861 0.1861 0.0207 0.0207 0.0000 0.0207 0.0207 0.0207 0.0000 0.0000 0.0414 0.0414 0.0414 0.1034 0.0620 0.0000 0.0000 0.0000 0.0000
]’;
hour = (1:24)’;
Starting_Probability = table(hour, rice_cooker, blender);
Starting_Probability.Properties.VariableNames{‘rice_cooker’} = ‘Rice_Cooker’;
Starting_Probability.Properties.VariableNames{‘blender’} = ‘Blender’;
% Import data into another table
cycle_t_first_column = [0 0 0 0 41 32 31 30 0 0 30 30 15 40 0 0 0 20 35 29 45 0 0 0
]’;
cycle_t_second_column = [0 0 0 0 10 8 7 9 15 0 13 18 21 10 15 0 9 11 8 7 10 0 0 0
]’;
cycle_t = table(cycle_t_first_column,cycle_t_second_column);
cycle_t.Properties.VariableNames{‘cycle_t_first_column’} = ‘Rice_Cooker’;
cycle_t.Properties.VariableNames{‘cycle_t_second_column’} = ‘Blender’;
% Import data into another table
app_pwr_first_column = [0.000 0.000 0.000 0.000 1.525 1.271 1.220 0.700 0.000 0.000 1.400 1.550 1.000 1.333 0.000 0.000 0.000 1.300 1.600 1.260 1.500 0.000 0.000 0.000
]’;
app_pwr_second_column = [0.000 0.000 0.000 0.000 0.550 0.543 0.682 0.325 0.978 0.000 0.328 0.365 0.525 0.775 0.374 0.000 0.138 0.494 0.567 0.507 2.000 0.000 0.000 0.000
]’;
app_pwr = table(app_pwr_first_column,app_pwr_second_column);
app_pwr.Properties.VariableNames{‘app_pwr_first_column’} = ‘Rice_Cooker’;
app_pwr.Properties.VariableNames{‘app_pwr_second_column’} = ‘Blender’;
app_pwr.Properties.RowNames = cellstr(num2str((1:24)’));
% Create a table named Power_usage with two columns and 24 rows
Power_usage = table(zeros(24,1), zeros(24,1));
% Rename the columns as RiceCooker and Blender
Power_usage.Properties.VariableNames = {‘Rice_Cooker’, ‘Blender’};
% Rename the rows as 1 to 24
Power_usage.Properties.RowNames = cellstr(num2str((1:24)’));
% Get the values of Tstart and Applno variables
Tstart = 2; %input(‘Enter the value of Tstart: ‘);
Applno = 1; %input(‘Enter the value of Applno: ‘);
%% Create a loop until Tstart equals 24
while Tstart <= 24
% Generate 100 random numbers between 0 and 1
x = rand(100,1);
% Assign the 100th random number to a variable named r
r = x(100);
% Check the random number against the element of T table
if Applno == 1 % RiceCooker column
if r < Starting_Probability.Rice_Cooker(Tstart) % Random number is greater than element value
% Read the value from app_pwr table and store it in Power_usage table
Power_usage.Rice_Cooker(Tstart) = app_pwr.Rice_Cooker(Tstart);
else % Random number is less than element value
% Store 0 in Power_usage table
Power_usage.Rice_Cooker(Tstart) = 0;
end
elseif Applno == 2 % Blender column
if r < Starting_Probability.Blender(Tstart) % Random number is greater than element value
% Read the value from app_pwr table and store it in Power_usage table
Power_usage.Blender(Tstart) = app_pwr.Blender(Tstart);
else % Random number is less than element value
% Store 0 in Power_usage table
Power_usage.Blender(Tstart) = 0;
end
end
% Get the value of Tcycle from cycle_t table
if Applno == 1 % RiceCooker column
Tcycle = cycle_t.Rice_Cooker(Tstart);
elseif Applno == 2 % Blender column
Tcycle = cycle_t.Blender(Tstart);
end
% Update Tstart as per the equation
Tstart = Tstart + Tcycle;
end
% I’m getting an error at the Power_usage.Rice_Cooker(Tstart) = 0; line % Import data into a table
rice_cooker = [0.0000 0.0000 0.0000 0.0000 0.0863 0.5180 0.4317 0.0432 0.0863 0.0000 0.0000 0.0432 0.1295 0.1295 0.0000 0.0000 0.0000 0.0863 0.4748 0.3885 0.0432 0.0000 0.0000 0.0000]’;
blender = [0.0000 0.0000 0.0000 0.0000 0.0207 0.1861 0.1861 0.0207 0.0207 0.0000 0.0207 0.0207 0.0207 0.0000 0.0000 0.0414 0.0414 0.0414 0.1034 0.0620 0.0000 0.0000 0.0000 0.0000
]’;
hour = (1:24)’;
Starting_Probability = table(hour, rice_cooker, blender);
Starting_Probability.Properties.VariableNames{‘rice_cooker’} = ‘Rice_Cooker’;
Starting_Probability.Properties.VariableNames{‘blender’} = ‘Blender’;
% Import data into another table
cycle_t_first_column = [0 0 0 0 41 32 31 30 0 0 30 30 15 40 0 0 0 20 35 29 45 0 0 0
]’;
cycle_t_second_column = [0 0 0 0 10 8 7 9 15 0 13 18 21 10 15 0 9 11 8 7 10 0 0 0
]’;
cycle_t = table(cycle_t_first_column,cycle_t_second_column);
cycle_t.Properties.VariableNames{‘cycle_t_first_column’} = ‘Rice_Cooker’;
cycle_t.Properties.VariableNames{‘cycle_t_second_column’} = ‘Blender’;
% Import data into another table
app_pwr_first_column = [0.000 0.000 0.000 0.000 1.525 1.271 1.220 0.700 0.000 0.000 1.400 1.550 1.000 1.333 0.000 0.000 0.000 1.300 1.600 1.260 1.500 0.000 0.000 0.000
]’;
app_pwr_second_column = [0.000 0.000 0.000 0.000 0.550 0.543 0.682 0.325 0.978 0.000 0.328 0.365 0.525 0.775 0.374 0.000 0.138 0.494 0.567 0.507 2.000 0.000 0.000 0.000
]’;
app_pwr = table(app_pwr_first_column,app_pwr_second_column);
app_pwr.Properties.VariableNames{‘app_pwr_first_column’} = ‘Rice_Cooker’;
app_pwr.Properties.VariableNames{‘app_pwr_second_column’} = ‘Blender’;
app_pwr.Properties.RowNames = cellstr(num2str((1:24)’));
% Create a table named Power_usage with two columns and 24 rows
Power_usage = table(zeros(24,1), zeros(24,1));
% Rename the columns as RiceCooker and Blender
Power_usage.Properties.VariableNames = {‘Rice_Cooker’, ‘Blender’};
% Rename the rows as 1 to 24
Power_usage.Properties.RowNames = cellstr(num2str((1:24)’));
% Get the values of Tstart and Applno variables
Tstart = 2; %input(‘Enter the value of Tstart: ‘);
Applno = 1; %input(‘Enter the value of Applno: ‘);
%% Create a loop until Tstart equals 24
while Tstart <= 24
% Generate 100 random numbers between 0 and 1
x = rand(100,1);
% Assign the 100th random number to a variable named r
r = x(100);
% Check the random number against the element of T table
if Applno == 1 % RiceCooker column
if r < Starting_Probability.Rice_Cooker(Tstart) % Random number is greater than element value
% Read the value from app_pwr table and store it in Power_usage table
Power_usage.Rice_Cooker(Tstart) = app_pwr.Rice_Cooker(Tstart);
else % Random number is less than element value
% Store 0 in Power_usage table
Power_usage.Rice_Cooker(Tstart) = 0;
end
elseif Applno == 2 % Blender column
if r < Starting_Probability.Blender(Tstart) % Random number is greater than element value
% Read the value from app_pwr table and store it in Power_usage table
Power_usage.Blender(Tstart) = app_pwr.Blender(Tstart);
else % Random number is less than element value
% Store 0 in Power_usage table
Power_usage.Blender(Tstart) = 0;
end
end
% Get the value of Tcycle from cycle_t table
if Applno == 1 % RiceCooker column
Tcycle = cycle_t.Rice_Cooker(Tstart);
elseif Applno == 2 % Blender column
Tcycle = cycle_t.Blender(Tstart);
end
% Update Tstart as per the equation
Tstart = Tstart + Tcycle;
end
% I’m getting an error at the Power_usage.Rice_Cooker(Tstart) = 0; line load modelling MATLAB Answers — New Questions