Category: Matlab
Category Archives: Matlab
how can i create a smooth curve through data points
from this code Matlab, how can I create a smooth curve through data points? As shown in the figure.
clear
clc
x=-0.6745:0.06745:0.6745;
x1=-0.6499:0.06499:0.6499;
x2=-0.5856:0.05856:0.5856;
f=[21.0956 20.4078 19.6966 18.9596 18.1937 17.3952 16.5596 15.6810 14.7522 13.7634 12.7012 11.5462 10.2690 8.8199 7.1021 4.8672 0.0048 4.8672 7.1021 8.8199 10.2690 ];
f1=[20.7378 20.0626 19.3646 18.6411 17.8892 17.1054 16.2850 15.4225 14.5107 13.5400 12.5972 11.3633 10.1093 8.6865 6.9997 4.8045 0.01215 4.8045 6.9997 8.6865 10.1093];
f2=[19.7669 19.1259 18.4632 17.7764 17.0626 16.3185 15.5396 14.7208 13.8552 12.9336 11.9435 10.8669 9.6763 8.3251 6.7231 4.6374 0.0090 4.6374 6.7231 8.3251 9.6763];
figure
h=plot(x,f,’-o’,x1,f1,’-o’,x2,f2,’k-o’);
set(h(1),’Color’,[0.6350 0.0780 0.1840]);
set(h(2),’Color’,[0.4660 0.6740 0.1880]);
title(‘(a)’);
hXL=xlabel(‘V(Volt)’,’FontSize’,11,’FontWeight’,’bold’);
hXL1=ylabel(‘{omega(Ghz)}’,’FontSize’,11,’FontWeight’,’bold’,’Rotation’,0);
hXL1.Position=hXL.Position+[-0.7 12 0];
lgd1 = legend(‘{itb_w} {mu=0}’,'{itb_w} {mu=1nm}’,'{itb_w} {mu=2nm}’);
lgd1.FontSize=9;
xlim([-0.6 0.6]);
xticks(-0.6:0.2:0.6);
ylim([0 22]);
grid minor
grid onfrom this code Matlab, how can I create a smooth curve through data points? As shown in the figure.
clear
clc
x=-0.6745:0.06745:0.6745;
x1=-0.6499:0.06499:0.6499;
x2=-0.5856:0.05856:0.5856;
f=[21.0956 20.4078 19.6966 18.9596 18.1937 17.3952 16.5596 15.6810 14.7522 13.7634 12.7012 11.5462 10.2690 8.8199 7.1021 4.8672 0.0048 4.8672 7.1021 8.8199 10.2690 ];
f1=[20.7378 20.0626 19.3646 18.6411 17.8892 17.1054 16.2850 15.4225 14.5107 13.5400 12.5972 11.3633 10.1093 8.6865 6.9997 4.8045 0.01215 4.8045 6.9997 8.6865 10.1093];
f2=[19.7669 19.1259 18.4632 17.7764 17.0626 16.3185 15.5396 14.7208 13.8552 12.9336 11.9435 10.8669 9.6763 8.3251 6.7231 4.6374 0.0090 4.6374 6.7231 8.3251 9.6763];
figure
h=plot(x,f,’-o’,x1,f1,’-o’,x2,f2,’k-o’);
set(h(1),’Color’,[0.6350 0.0780 0.1840]);
set(h(2),’Color’,[0.4660 0.6740 0.1880]);
title(‘(a)’);
hXL=xlabel(‘V(Volt)’,’FontSize’,11,’FontWeight’,’bold’);
hXL1=ylabel(‘{omega(Ghz)}’,’FontSize’,11,’FontWeight’,’bold’,’Rotation’,0);
hXL1.Position=hXL.Position+[-0.7 12 0];
lgd1 = legend(‘{itb_w} {mu=0}’,'{itb_w} {mu=1nm}’,'{itb_w} {mu=2nm}’);
lgd1.FontSize=9;
xlim([-0.6 0.6]);
xticks(-0.6:0.2:0.6);
ylim([0 22]);
grid minor
grid on from this code Matlab, how can I create a smooth curve through data points? As shown in the figure.
clear
clc
x=-0.6745:0.06745:0.6745;
x1=-0.6499:0.06499:0.6499;
x2=-0.5856:0.05856:0.5856;
f=[21.0956 20.4078 19.6966 18.9596 18.1937 17.3952 16.5596 15.6810 14.7522 13.7634 12.7012 11.5462 10.2690 8.8199 7.1021 4.8672 0.0048 4.8672 7.1021 8.8199 10.2690 ];
f1=[20.7378 20.0626 19.3646 18.6411 17.8892 17.1054 16.2850 15.4225 14.5107 13.5400 12.5972 11.3633 10.1093 8.6865 6.9997 4.8045 0.01215 4.8045 6.9997 8.6865 10.1093];
f2=[19.7669 19.1259 18.4632 17.7764 17.0626 16.3185 15.5396 14.7208 13.8552 12.9336 11.9435 10.8669 9.6763 8.3251 6.7231 4.6374 0.0090 4.6374 6.7231 8.3251 9.6763];
figure
h=plot(x,f,’-o’,x1,f1,’-o’,x2,f2,’k-o’);
set(h(1),’Color’,[0.6350 0.0780 0.1840]);
set(h(2),’Color’,[0.4660 0.6740 0.1880]);
title(‘(a)’);
hXL=xlabel(‘V(Volt)’,’FontSize’,11,’FontWeight’,’bold’);
hXL1=ylabel(‘{omega(Ghz)}’,’FontSize’,11,’FontWeight’,’bold’,’Rotation’,0);
hXL1.Position=hXL.Position+[-0.7 12 0];
lgd1 = legend(‘{itb_w} {mu=0}’,'{itb_w} {mu=1nm}’,'{itb_w} {mu=2nm}’);
lgd1.FontSize=9;
xlim([-0.6 0.6]);
xticks(-0.6:0.2:0.6);
ylim([0 22]);
grid minor
grid on plotting, 2d plot MATLAB Answers — New Questions
how can i create a smooth curve through data points
from this code Matlab, how can I create a smooth curve through data points? As shown in the figure.
clear
clc
x=-0.6745:0.06745:0.6745;
x1=-0.6499:0.06499:0.6499;
x2=-0.5856:0.05856:0.5856;
f=[21.0956 20.4078 19.6966 18.9596 18.1937 17.3952 16.5596 15.6810 14.7522 13.7634 12.7012 11.5462 10.2690 8.8199 7.1021 4.8672 0.0048 4.8672 7.1021 8.8199 10.2690 ];
f1=[20.7378 20.0626 19.3646 18.6411 17.8892 17.1054 16.2850 15.4225 14.5107 13.5400 12.5972 11.3633 10.1093 8.6865 6.9997 4.8045 0.01215 4.8045 6.9997 8.6865 10.1093];
f2=[19.7669 19.1259 18.4632 17.7764 17.0626 16.3185 15.5396 14.7208 13.8552 12.9336 11.9435 10.8669 9.6763 8.3251 6.7231 4.6374 0.0090 4.6374 6.7231 8.3251 9.6763];
figure
h=plot(x,f,’-o’,x1,f1,’-o’,x2,f2,’k-o’);
set(h(1),’Color’,[0.6350 0.0780 0.1840]);
set(h(2),’Color’,[0.4660 0.6740 0.1880]);
title(‘(a)’);
hXL=xlabel(‘V(Volt)’,’FontSize’,11,’FontWeight’,’bold’);
hXL1=ylabel(‘{omega(Ghz)}’,’FontSize’,11,’FontWeight’,’bold’,’Rotation’,0);
hXL1.Position=hXL.Position+[-0.7 12 0];
lgd1 = legend(‘{itb_w} {mu=0}’,'{itb_w} {mu=1nm}’,'{itb_w} {mu=2nm}’);
lgd1.FontSize=9;
xlim([-0.6 0.6]);
xticks(-0.6:0.2:0.6);
ylim([0 22]);
grid minor
grid onfrom this code Matlab, how can I create a smooth curve through data points? As shown in the figure.
clear
clc
x=-0.6745:0.06745:0.6745;
x1=-0.6499:0.06499:0.6499;
x2=-0.5856:0.05856:0.5856;
f=[21.0956 20.4078 19.6966 18.9596 18.1937 17.3952 16.5596 15.6810 14.7522 13.7634 12.7012 11.5462 10.2690 8.8199 7.1021 4.8672 0.0048 4.8672 7.1021 8.8199 10.2690 ];
f1=[20.7378 20.0626 19.3646 18.6411 17.8892 17.1054 16.2850 15.4225 14.5107 13.5400 12.5972 11.3633 10.1093 8.6865 6.9997 4.8045 0.01215 4.8045 6.9997 8.6865 10.1093];
f2=[19.7669 19.1259 18.4632 17.7764 17.0626 16.3185 15.5396 14.7208 13.8552 12.9336 11.9435 10.8669 9.6763 8.3251 6.7231 4.6374 0.0090 4.6374 6.7231 8.3251 9.6763];
figure
h=plot(x,f,’-o’,x1,f1,’-o’,x2,f2,’k-o’);
set(h(1),’Color’,[0.6350 0.0780 0.1840]);
set(h(2),’Color’,[0.4660 0.6740 0.1880]);
title(‘(a)’);
hXL=xlabel(‘V(Volt)’,’FontSize’,11,’FontWeight’,’bold’);
hXL1=ylabel(‘{omega(Ghz)}’,’FontSize’,11,’FontWeight’,’bold’,’Rotation’,0);
hXL1.Position=hXL.Position+[-0.7 12 0];
lgd1 = legend(‘{itb_w} {mu=0}’,'{itb_w} {mu=1nm}’,'{itb_w} {mu=2nm}’);
lgd1.FontSize=9;
xlim([-0.6 0.6]);
xticks(-0.6:0.2:0.6);
ylim([0 22]);
grid minor
grid on from this code Matlab, how can I create a smooth curve through data points? As shown in the figure.
clear
clc
x=-0.6745:0.06745:0.6745;
x1=-0.6499:0.06499:0.6499;
x2=-0.5856:0.05856:0.5856;
f=[21.0956 20.4078 19.6966 18.9596 18.1937 17.3952 16.5596 15.6810 14.7522 13.7634 12.7012 11.5462 10.2690 8.8199 7.1021 4.8672 0.0048 4.8672 7.1021 8.8199 10.2690 ];
f1=[20.7378 20.0626 19.3646 18.6411 17.8892 17.1054 16.2850 15.4225 14.5107 13.5400 12.5972 11.3633 10.1093 8.6865 6.9997 4.8045 0.01215 4.8045 6.9997 8.6865 10.1093];
f2=[19.7669 19.1259 18.4632 17.7764 17.0626 16.3185 15.5396 14.7208 13.8552 12.9336 11.9435 10.8669 9.6763 8.3251 6.7231 4.6374 0.0090 4.6374 6.7231 8.3251 9.6763];
figure
h=plot(x,f,’-o’,x1,f1,’-o’,x2,f2,’k-o’);
set(h(1),’Color’,[0.6350 0.0780 0.1840]);
set(h(2),’Color’,[0.4660 0.6740 0.1880]);
title(‘(a)’);
hXL=xlabel(‘V(Volt)’,’FontSize’,11,’FontWeight’,’bold’);
hXL1=ylabel(‘{omega(Ghz)}’,’FontSize’,11,’FontWeight’,’bold’,’Rotation’,0);
hXL1.Position=hXL.Position+[-0.7 12 0];
lgd1 = legend(‘{itb_w} {mu=0}’,'{itb_w} {mu=1nm}’,'{itb_w} {mu=2nm}’);
lgd1.FontSize=9;
xlim([-0.6 0.6]);
xticks(-0.6:0.2:0.6);
ylim([0 22]);
grid minor
grid on plotting, 2d plot MATLAB Answers — New Questions
i cant synchronize lidar and camera together for fusion
this my code when i move camera detects that am moving then 5 seconds later i start moving in the lidar
% lidarFig = subplot(1, 2, 2); % Create subplot for lidar data
countinueStreaming = true;
while countinueStreaming
% Record the current timestamp before capturing the image
% Capture the image from the Jetson camera hardware.
I = snapshot(cam);
% Record the timestamp after capturing the image
% Call to detect method
[bboxes, scores, labels] = detect(detector, I);
personIndices = find(labels == ‘person’);
personBboxes = bboxes(personIndices, :);
% Convert categorical labels to cell array of character vectors
labels = cellstr(labels);
% Annotate detections in the camera image.
img = insertObjectAnnotation(I, ‘rectangle’, bboxes, labels);
% Display camera image
imshow(img);
hold on;
% Read data from Velodyne Lidar
pc = read(lidar);
% Remove ground plane
groundPtsIndex = segmentGroundFromLidarData(pc, ‘ElevationAngleDelta’, 0, …
‘InitialElevationAngle’, 0);
nonGroundPts = select(pc, ~groundPtsIndex);
imPts = projectLidarPointsOnImage(pc, intrinsics, LidarToCam);
scatter(imPts(:, 1), imPts(:, 2), 10, ‘g’, ‘filled’);
% Display lidar data
% pcshow(nonGroundPts.Location, ‘Parent’, lidarFig);
if ~isempty(personIndices)
for i = 1:numel(personIndices)
index = personIndices(i);
personBbox = bboxes(index, :);
% Process lidar data for each detected person
[lidarBbox, ~, boxUsed] = bboxCameraToLidar(personBbox, nonGroundPts, intrinsics, …
camToLidar, ‘ClusterThreshold’, 2, ‘MaxDetectionRange’, [1, 10]);
[distance, nearestRect, idx] = helperComputeDistance(personBbox, nonGroundPts, lidarBbox, …
intrinsics, LidarToCam);
% Print distance information
fprintf(‘DistOfPerson %d: %.2f metersn’, i, distance);
% Update image with bounding boxes
% im = updateImage(display, im, nearestRect, distance);
% updateLidarBbox(display, lidarBbox)
end
else
% Process lidar data for other objects
[lidarBbox, ~, boxUsed] = bboxCameraToLidar(bboxes, nonGroundPts, intrinsics, …
camToLidar, ‘ClusterThreshold’, 2, ‘MaxDetectionRange’, [1, 10]);
[distance, nearestRect, idx] = helperComputeDistance(bboxes, nonGroundPts, lidarBbox, …
intrinsics, LidarToCam);
% Print distance information
fprintf(‘DistOfObj: %.2f metersn’, distance);
% Update image with bounding boxes
% im = updateImage(display, im, nearestRect, distance);
% updateLidarBbox(display, lidarBbox)
end
hold off;
endthis my code when i move camera detects that am moving then 5 seconds later i start moving in the lidar
% lidarFig = subplot(1, 2, 2); % Create subplot for lidar data
countinueStreaming = true;
while countinueStreaming
% Record the current timestamp before capturing the image
% Capture the image from the Jetson camera hardware.
I = snapshot(cam);
% Record the timestamp after capturing the image
% Call to detect method
[bboxes, scores, labels] = detect(detector, I);
personIndices = find(labels == ‘person’);
personBboxes = bboxes(personIndices, :);
% Convert categorical labels to cell array of character vectors
labels = cellstr(labels);
% Annotate detections in the camera image.
img = insertObjectAnnotation(I, ‘rectangle’, bboxes, labels);
% Display camera image
imshow(img);
hold on;
% Read data from Velodyne Lidar
pc = read(lidar);
% Remove ground plane
groundPtsIndex = segmentGroundFromLidarData(pc, ‘ElevationAngleDelta’, 0, …
‘InitialElevationAngle’, 0);
nonGroundPts = select(pc, ~groundPtsIndex);
imPts = projectLidarPointsOnImage(pc, intrinsics, LidarToCam);
scatter(imPts(:, 1), imPts(:, 2), 10, ‘g’, ‘filled’);
% Display lidar data
% pcshow(nonGroundPts.Location, ‘Parent’, lidarFig);
if ~isempty(personIndices)
for i = 1:numel(personIndices)
index = personIndices(i);
personBbox = bboxes(index, :);
% Process lidar data for each detected person
[lidarBbox, ~, boxUsed] = bboxCameraToLidar(personBbox, nonGroundPts, intrinsics, …
camToLidar, ‘ClusterThreshold’, 2, ‘MaxDetectionRange’, [1, 10]);
[distance, nearestRect, idx] = helperComputeDistance(personBbox, nonGroundPts, lidarBbox, …
intrinsics, LidarToCam);
% Print distance information
fprintf(‘DistOfPerson %d: %.2f metersn’, i, distance);
% Update image with bounding boxes
% im = updateImage(display, im, nearestRect, distance);
% updateLidarBbox(display, lidarBbox)
end
else
% Process lidar data for other objects
[lidarBbox, ~, boxUsed] = bboxCameraToLidar(bboxes, nonGroundPts, intrinsics, …
camToLidar, ‘ClusterThreshold’, 2, ‘MaxDetectionRange’, [1, 10]);
[distance, nearestRect, idx] = helperComputeDistance(bboxes, nonGroundPts, lidarBbox, …
intrinsics, LidarToCam);
% Print distance information
fprintf(‘DistOfObj: %.2f metersn’, distance);
% Update image with bounding boxes
% im = updateImage(display, im, nearestRect, distance);
% updateLidarBbox(display, lidarBbox)
end
hold off;
end this my code when i move camera detects that am moving then 5 seconds later i start moving in the lidar
% lidarFig = subplot(1, 2, 2); % Create subplot for lidar data
countinueStreaming = true;
while countinueStreaming
% Record the current timestamp before capturing the image
% Capture the image from the Jetson camera hardware.
I = snapshot(cam);
% Record the timestamp after capturing the image
% Call to detect method
[bboxes, scores, labels] = detect(detector, I);
personIndices = find(labels == ‘person’);
personBboxes = bboxes(personIndices, :);
% Convert categorical labels to cell array of character vectors
labels = cellstr(labels);
% Annotate detections in the camera image.
img = insertObjectAnnotation(I, ‘rectangle’, bboxes, labels);
% Display camera image
imshow(img);
hold on;
% Read data from Velodyne Lidar
pc = read(lidar);
% Remove ground plane
groundPtsIndex = segmentGroundFromLidarData(pc, ‘ElevationAngleDelta’, 0, …
‘InitialElevationAngle’, 0);
nonGroundPts = select(pc, ~groundPtsIndex);
imPts = projectLidarPointsOnImage(pc, intrinsics, LidarToCam);
scatter(imPts(:, 1), imPts(:, 2), 10, ‘g’, ‘filled’);
% Display lidar data
% pcshow(nonGroundPts.Location, ‘Parent’, lidarFig);
if ~isempty(personIndices)
for i = 1:numel(personIndices)
index = personIndices(i);
personBbox = bboxes(index, :);
% Process lidar data for each detected person
[lidarBbox, ~, boxUsed] = bboxCameraToLidar(personBbox, nonGroundPts, intrinsics, …
camToLidar, ‘ClusterThreshold’, 2, ‘MaxDetectionRange’, [1, 10]);
[distance, nearestRect, idx] = helperComputeDistance(personBbox, nonGroundPts, lidarBbox, …
intrinsics, LidarToCam);
% Print distance information
fprintf(‘DistOfPerson %d: %.2f metersn’, i, distance);
% Update image with bounding boxes
% im = updateImage(display, im, nearestRect, distance);
% updateLidarBbox(display, lidarBbox)
end
else
% Process lidar data for other objects
[lidarBbox, ~, boxUsed] = bboxCameraToLidar(bboxes, nonGroundPts, intrinsics, …
camToLidar, ‘ClusterThreshold’, 2, ‘MaxDetectionRange’, [1, 10]);
[distance, nearestRect, idx] = helperComputeDistance(bboxes, nonGroundPts, lidarBbox, …
intrinsics, LidarToCam);
% Print distance information
fprintf(‘DistOfObj: %.2f metersn’, distance);
% Update image with bounding boxes
% im = updateImage(display, im, nearestRect, distance);
% updateLidarBbox(display, lidarBbox)
end
hold off;
end matlab code, fusion MATLAB Answers — New Questions
How do I break an array into individual element without using loops
x=[3,4,5,6,7,8,9,10]
for i=1:length(x)
y=x(i)
end
I want a function to give me this result without using a loopx=[3,4,5,6,7,8,9,10]
for i=1:length(x)
y=x(i)
end
I want a function to give me this result without using a loop x=[3,4,5,6,7,8,9,10]
for i=1:length(x)
y=x(i)
end
I want a function to give me this result without using a loop array, bad idea MATLAB Answers — New Questions
How do I break an array into individual element without using loops
x=[3,4,5,6,7,8,9,10]
for i=1:length(x)
y=x(i)
end
I want a function to give me this result without using a loopx=[3,4,5,6,7,8,9,10]
for i=1:length(x)
y=x(i)
end
I want a function to give me this result without using a loop x=[3,4,5,6,7,8,9,10]
for i=1:length(x)
y=x(i)
end
I want a function to give me this result without using a loop array MATLAB Answers — New Questions
Training deep learning network on GPU is significantly slower than using CPU
I am training a CNN-LSTM regression network on matlab 2023b.
layers = […
sequenceInputLayer([1440 1 1],’Name’,’input’)
flattenLayer(‘Name’,’flatten’)
convolution1dLayer(5,2,’Padding’,’same’,’WeightsInitializer’,’he’,’Name’,’conv’,’DilationFactor’,1);
batchNormalizationLayer(‘Name’,’bn’)
reluLayer(‘Name’,’relu’)
lstmLayer(24,’OutputMode’,"last",’Name’,’bil4′,’RecurrentWeightsInitializer’,’He’,’InputWeightsInitializer’,’He’)
dropoutLayer(0.1,’Name’,’drop3′)
fullyConnectedLayer(1,’Name’,’fc’)
regressionLayer(‘Name’,’output’) ];
MaxEpochs = 200;
learningrate = 0.0061;
learningrate = 0.001;
MiniBatchSize = 64;
solver = ‘adam’;
options = trainingOptions(solver, …
‘MaxEpochs’,MaxEpochs, …
‘GradientThreshold’,1, …
‘InitialLearnRate’,learningrate, …
‘LearnRateSchedule’,"piecewise", …
‘LearnRateDropPeriod’,96, …
‘LearnRateDropFactor’,0.25, …
‘MiniBatchSize’,MiniBatchSize,…
‘Verbose’,false, …
‘Shuffle’,"every-epoch",…
‘ExecutionEnvironment’,mydevice,…
‘Plots’,’training-progress’);
[net,info] = trainNetwork(XrTrain,YrTrain,layers,options);
My GPU is an NVIDIA RTX A4500. However, when I use GPU for training (mydevice = ‘gpu’), the training speed is significantly slower than using CPU. Only 15223 iterations are completed in 5min using GPU, while 30372 iterations are completed using CPU.
The training results are acctually both good regardless of using GPU or CPU. The only difference is the time consumed. The GPU usage in Windows Task Manager is around 80% to 100% during training.
Could anyone please help with this problem? Are there special settings that need to be applied when training a DL network using GPU?I am training a CNN-LSTM regression network on matlab 2023b.
layers = […
sequenceInputLayer([1440 1 1],’Name’,’input’)
flattenLayer(‘Name’,’flatten’)
convolution1dLayer(5,2,’Padding’,’same’,’WeightsInitializer’,’he’,’Name’,’conv’,’DilationFactor’,1);
batchNormalizationLayer(‘Name’,’bn’)
reluLayer(‘Name’,’relu’)
lstmLayer(24,’OutputMode’,"last",’Name’,’bil4′,’RecurrentWeightsInitializer’,’He’,’InputWeightsInitializer’,’He’)
dropoutLayer(0.1,’Name’,’drop3′)
fullyConnectedLayer(1,’Name’,’fc’)
regressionLayer(‘Name’,’output’) ];
MaxEpochs = 200;
learningrate = 0.0061;
learningrate = 0.001;
MiniBatchSize = 64;
solver = ‘adam’;
options = trainingOptions(solver, …
‘MaxEpochs’,MaxEpochs, …
‘GradientThreshold’,1, …
‘InitialLearnRate’,learningrate, …
‘LearnRateSchedule’,"piecewise", …
‘LearnRateDropPeriod’,96, …
‘LearnRateDropFactor’,0.25, …
‘MiniBatchSize’,MiniBatchSize,…
‘Verbose’,false, …
‘Shuffle’,"every-epoch",…
‘ExecutionEnvironment’,mydevice,…
‘Plots’,’training-progress’);
[net,info] = trainNetwork(XrTrain,YrTrain,layers,options);
My GPU is an NVIDIA RTX A4500. However, when I use GPU for training (mydevice = ‘gpu’), the training speed is significantly slower than using CPU. Only 15223 iterations are completed in 5min using GPU, while 30372 iterations are completed using CPU.
The training results are acctually both good regardless of using GPU or CPU. The only difference is the time consumed. The GPU usage in Windows Task Manager is around 80% to 100% during training.
Could anyone please help with this problem? Are there special settings that need to be applied when training a DL network using GPU? I am training a CNN-LSTM regression network on matlab 2023b.
layers = […
sequenceInputLayer([1440 1 1],’Name’,’input’)
flattenLayer(‘Name’,’flatten’)
convolution1dLayer(5,2,’Padding’,’same’,’WeightsInitializer’,’he’,’Name’,’conv’,’DilationFactor’,1);
batchNormalizationLayer(‘Name’,’bn’)
reluLayer(‘Name’,’relu’)
lstmLayer(24,’OutputMode’,"last",’Name’,’bil4′,’RecurrentWeightsInitializer’,’He’,’InputWeightsInitializer’,’He’)
dropoutLayer(0.1,’Name’,’drop3′)
fullyConnectedLayer(1,’Name’,’fc’)
regressionLayer(‘Name’,’output’) ];
MaxEpochs = 200;
learningrate = 0.0061;
learningrate = 0.001;
MiniBatchSize = 64;
solver = ‘adam’;
options = trainingOptions(solver, …
‘MaxEpochs’,MaxEpochs, …
‘GradientThreshold’,1, …
‘InitialLearnRate’,learningrate, …
‘LearnRateSchedule’,"piecewise", …
‘LearnRateDropPeriod’,96, …
‘LearnRateDropFactor’,0.25, …
‘MiniBatchSize’,MiniBatchSize,…
‘Verbose’,false, …
‘Shuffle’,"every-epoch",…
‘ExecutionEnvironment’,mydevice,…
‘Plots’,’training-progress’);
[net,info] = trainNetwork(XrTrain,YrTrain,layers,options);
My GPU is an NVIDIA RTX A4500. However, when I use GPU for training (mydevice = ‘gpu’), the training speed is significantly slower than using CPU. Only 15223 iterations are completed in 5min using GPU, while 30372 iterations are completed using CPU.
The training results are acctually both good regardless of using GPU or CPU. The only difference is the time consumed. The GPU usage in Windows Task Manager is around 80% to 100% during training.
Could anyone please help with this problem? Are there special settings that need to be applied when training a DL network using GPU? gpu, deep learning, neural network MATLAB Answers — New Questions
Training deep learning network on GPU is significantly slower than using CPU
I am training a CNN-LSTM regression network on matlab 2023b.
layers = […
sequenceInputLayer([1440 1 1],’Name’,’input’)
flattenLayer(‘Name’,’flatten’)
convolution1dLayer(5,2,’Padding’,’same’,’WeightsInitializer’,’he’,’Name’,’conv’,’DilationFactor’,1);
batchNormalizationLayer(‘Name’,’bn’)
reluLayer(‘Name’,’relu’)
lstmLayer(24,’OutputMode’,"last",’Name’,’bil4′,’RecurrentWeightsInitializer’,’He’,’InputWeightsInitializer’,’He’)
dropoutLayer(0.1,’Name’,’drop3′)
fullyConnectedLayer(1,’Name’,’fc’)
regressionLayer(‘Name’,’output’) ];
MaxEpochs = 200;
learningrate = 0.0061;
learningrate = 0.001;
MiniBatchSize = 64;
solver = ‘adam’;
options = trainingOptions(solver, …
‘MaxEpochs’,MaxEpochs, …
‘GradientThreshold’,1, …
‘InitialLearnRate’,learningrate, …
‘LearnRateSchedule’,"piecewise", …
‘LearnRateDropPeriod’,96, …
‘LearnRateDropFactor’,0.25, …
‘MiniBatchSize’,MiniBatchSize,…
‘Verbose’,false, …
‘Shuffle’,"every-epoch",…
‘ExecutionEnvironment’,mydevice,…
‘Plots’,’training-progress’);
[net,info] = trainNetwork(XrTrain,YrTrain,layers,options);
My GPU is an NVIDIA RTX A4500. However, when I use GPU for training (mydevice = ‘gpu’), the training speed is significantly slower than using CPU. Only 15223 iterations are completed in 5min using GPU, while 30372 iterations are completed using CPU.
The training results are acctually both good regardless of using GPU or CPU. The only difference is the time consumed. The GPU usage in Windows Task Manager is around 80% to 100% during training.
Could anyone please help with this problem? Are there special settings that need to be applied when training a DL network using GPU?I am training a CNN-LSTM regression network on matlab 2023b.
layers = […
sequenceInputLayer([1440 1 1],’Name’,’input’)
flattenLayer(‘Name’,’flatten’)
convolution1dLayer(5,2,’Padding’,’same’,’WeightsInitializer’,’he’,’Name’,’conv’,’DilationFactor’,1);
batchNormalizationLayer(‘Name’,’bn’)
reluLayer(‘Name’,’relu’)
lstmLayer(24,’OutputMode’,"last",’Name’,’bil4′,’RecurrentWeightsInitializer’,’He’,’InputWeightsInitializer’,’He’)
dropoutLayer(0.1,’Name’,’drop3′)
fullyConnectedLayer(1,’Name’,’fc’)
regressionLayer(‘Name’,’output’) ];
MaxEpochs = 200;
learningrate = 0.0061;
learningrate = 0.001;
MiniBatchSize = 64;
solver = ‘adam’;
options = trainingOptions(solver, …
‘MaxEpochs’,MaxEpochs, …
‘GradientThreshold’,1, …
‘InitialLearnRate’,learningrate, …
‘LearnRateSchedule’,"piecewise", …
‘LearnRateDropPeriod’,96, …
‘LearnRateDropFactor’,0.25, …
‘MiniBatchSize’,MiniBatchSize,…
‘Verbose’,false, …
‘Shuffle’,"every-epoch",…
‘ExecutionEnvironment’,mydevice,…
‘Plots’,’training-progress’);
[net,info] = trainNetwork(XrTrain,YrTrain,layers,options);
My GPU is an NVIDIA RTX A4500. However, when I use GPU for training (mydevice = ‘gpu’), the training speed is significantly slower than using CPU. Only 15223 iterations are completed in 5min using GPU, while 30372 iterations are completed using CPU.
The training results are acctually both good regardless of using GPU or CPU. The only difference is the time consumed. The GPU usage in Windows Task Manager is around 80% to 100% during training.
Could anyone please help with this problem? Are there special settings that need to be applied when training a DL network using GPU? I am training a CNN-LSTM regression network on matlab 2023b.
layers = […
sequenceInputLayer([1440 1 1],’Name’,’input’)
flattenLayer(‘Name’,’flatten’)
convolution1dLayer(5,2,’Padding’,’same’,’WeightsInitializer’,’he’,’Name’,’conv’,’DilationFactor’,1);
batchNormalizationLayer(‘Name’,’bn’)
reluLayer(‘Name’,’relu’)
lstmLayer(24,’OutputMode’,"last",’Name’,’bil4′,’RecurrentWeightsInitializer’,’He’,’InputWeightsInitializer’,’He’)
dropoutLayer(0.1,’Name’,’drop3′)
fullyConnectedLayer(1,’Name’,’fc’)
regressionLayer(‘Name’,’output’) ];
MaxEpochs = 200;
learningrate = 0.0061;
learningrate = 0.001;
MiniBatchSize = 64;
solver = ‘adam’;
options = trainingOptions(solver, …
‘MaxEpochs’,MaxEpochs, …
‘GradientThreshold’,1, …
‘InitialLearnRate’,learningrate, …
‘LearnRateSchedule’,"piecewise", …
‘LearnRateDropPeriod’,96, …
‘LearnRateDropFactor’,0.25, …
‘MiniBatchSize’,MiniBatchSize,…
‘Verbose’,false, …
‘Shuffle’,"every-epoch",…
‘ExecutionEnvironment’,mydevice,…
‘Plots’,’training-progress’);
[net,info] = trainNetwork(XrTrain,YrTrain,layers,options);
My GPU is an NVIDIA RTX A4500. However, when I use GPU for training (mydevice = ‘gpu’), the training speed is significantly slower than using CPU. Only 15223 iterations are completed in 5min using GPU, while 30372 iterations are completed using CPU.
The training results are acctually both good regardless of using GPU or CPU. The only difference is the time consumed. The GPU usage in Windows Task Manager is around 80% to 100% during training.
Could anyone please help with this problem? Are there special settings that need to be applied when training a DL network using GPU? gpu, deep learning, neural network MATLAB Answers — New Questions
Plotting the derivative of infected population SI model
Hello;
I’m trying to draw the following model
I tried the code ode45 but it didn’t work.
Is there a specific way to link to the same image? Thank you.Hello;
I’m trying to draw the following model
I tried the code ode45 but it didn’t work.
Is there a specific way to link to the same image? Thank you. Hello;
I’m trying to draw the following model
I tried the code ode45 but it didn’t work.
Is there a specific way to link to the same image? Thank you. si, matlab, plot MATLAB Answers — New Questions
How to find out area under the curved shape of the attached figure?
Post Content Post Content image processing, thresholding MATLAB Answers — New Questions
How to achieve this presentation of stateflow
As shown in the figure,How to achieve this presentation of stateflow,Thank you!As shown in the figure,How to achieve this presentation of stateflow,Thank you! As shown in the figure,How to achieve this presentation of stateflow,Thank you! stateflow, simulink MATLAB Answers — New Questions
matlab-support install stuck [Ubuntu 18.04]
I’ve just installed Matlab R2023b on Ubuntu 18.04, and after changing the installation folder permissions I’m able to open the program without issue. However, when I try downloading mat-lab support with sudo apt-get install matlab-support , the terminal stays stuck on "Preconfiguring packages…"
Haven’t found anything online that addresses this, and never run into in prior installs but hopefully it’s an easy fix.I’ve just installed Matlab R2023b on Ubuntu 18.04, and after changing the installation folder permissions I’m able to open the program without issue. However, when I try downloading mat-lab support with sudo apt-get install matlab-support , the terminal stays stuck on "Preconfiguring packages…"
Haven’t found anything online that addresses this, and never run into in prior installs but hopefully it’s an easy fix. I’ve just installed Matlab R2023b on Ubuntu 18.04, and after changing the installation folder permissions I’m able to open the program without issue. However, when I try downloading mat-lab support with sudo apt-get install matlab-support , the terminal stays stuck on "Preconfiguring packages…"
Haven’t found anything online that addresses this, and never run into in prior installs but hopefully it’s an easy fix. matlab-support, ubuntu, matlab MATLAB Answers — New Questions
Cell Balancing Model in Simulink
I have been working on Battery Model , in which i need to create a model for cell balancing of 3s-1p battery pack. And i am using passive cell balancing , with shunt resistor /bleed resistor and MOSFET as switch. So my question is how could i select the value of the shunt resistor.
Also how the stateflow chart balancing logic would exactly work.
What is required in the initialization script of cell balancing.I have been working on Battery Model , in which i need to create a model for cell balancing of 3s-1p battery pack. And i am using passive cell balancing , with shunt resistor /bleed resistor and MOSFET as switch. So my question is how could i select the value of the shunt resistor.
Also how the stateflow chart balancing logic would exactly work.
What is required in the initialization script of cell balancing. I have been working on Battery Model , in which i need to create a model for cell balancing of 3s-1p battery pack. And i am using passive cell balancing , with shunt resistor /bleed resistor and MOSFET as switch. So my question is how could i select the value of the shunt resistor.
Also how the stateflow chart balancing logic would exactly work.
What is required in the initialization script of cell balancing. simulink, simscape, matlab MATLAB Answers — New Questions
Plot error with plotting string values
Code is executing correctly but would like to have the original and the mutated strings on the plot
% Simulate DNA sequence evolution with mutations
sequenceLength = 50;
mutationRate = 0.02;
% Generate random DNA sequence
originalSequence = randsample([‘A’, ‘T’, ‘C’, ‘G’], sequenceLength, true);
% Introduce mutations
mutatedSequence = originalSequence;
mutationPositions = rand(1, sequenceLength) < mutationRate;
mutatedSequence(mutationPositions) = randsample(setdiff([‘A’, ‘T’, ‘C’, ‘G’], mutatedSequence(mutationPositions)), sum(mutationPositions), true);
% Display original and mutated sequences
disp(‘Original Sequence:’);
disp(originalSequence);
disp(‘Mutated Sequence:’);
disp(mutatedSequence);
% Bayesian Inference to detect mutations
priorProbabilityMutation = 0.01; % Prior probability of mutation
likelihoodMutation = mutationRate; % Likelihood of observing a mutation
% Bayes’ Theorem for each position
posteriorProbabilityMutation = zeros(1, sequenceLength);
for i = 1:sequenceLength
evidence = strcmp(originalSequence(i), mutatedSequence(i));
posteriorProbabilityMutation(i) = (likelihoodMutation * priorProbabilityMutation) / ((likelihoodMutation * priorProbabilityMutation) + (~evidence * (1 – priorProbabilityMutation)));
end
% Set a threshold for detecting mutations
threshold = 0.5;
detectedMutations = posteriorProbabilityMutation > threshold;
% Display results
disp(‘Posterior Probability of Mutation:’);
disp(posteriorProbabilityMutation);
disp(‘Detected Mutations:’);
disp(detectedMutations);
% Visualization
figure;
subplot(3, 1, 1);
bar(posteriorProbabilityMutation, ‘b’);
xlabel(‘Position’);
ylabel(‘Posterior Probability of Mutation’);
title(‘Bayesian Inference’);
grid on;
subplot(3, 1, 2);
plot(originalSequence, ‘bo’, ‘LineWidth’, 2);
hold on;
plot(mutatedSequence, ‘rx’, ‘LineWidth’, 2);
scatter(find(detectedMutations), ones(1, sum(detectedMutations)), ‘g’, ‘filled’);
legend(‘Original Sequence’, ‘Mutated Sequence’, ‘Detected Mutations’);
xlabel(‘Position’);
ylabel(‘Nucleotide’);
title(‘DNA Sequence and Mutations’);
grid on;
hold off;
subplot(3, 1, 3);
stem(detectedMutations, ‘r’, ‘LineWidth’, 2);
xlabel(‘Position’);
ylabel(‘Mutation Detected’);
title(‘Mutation Detection’);
grid on;Code is executing correctly but would like to have the original and the mutated strings on the plot
% Simulate DNA sequence evolution with mutations
sequenceLength = 50;
mutationRate = 0.02;
% Generate random DNA sequence
originalSequence = randsample([‘A’, ‘T’, ‘C’, ‘G’], sequenceLength, true);
% Introduce mutations
mutatedSequence = originalSequence;
mutationPositions = rand(1, sequenceLength) < mutationRate;
mutatedSequence(mutationPositions) = randsample(setdiff([‘A’, ‘T’, ‘C’, ‘G’], mutatedSequence(mutationPositions)), sum(mutationPositions), true);
% Display original and mutated sequences
disp(‘Original Sequence:’);
disp(originalSequence);
disp(‘Mutated Sequence:’);
disp(mutatedSequence);
% Bayesian Inference to detect mutations
priorProbabilityMutation = 0.01; % Prior probability of mutation
likelihoodMutation = mutationRate; % Likelihood of observing a mutation
% Bayes’ Theorem for each position
posteriorProbabilityMutation = zeros(1, sequenceLength);
for i = 1:sequenceLength
evidence = strcmp(originalSequence(i), mutatedSequence(i));
posteriorProbabilityMutation(i) = (likelihoodMutation * priorProbabilityMutation) / ((likelihoodMutation * priorProbabilityMutation) + (~evidence * (1 – priorProbabilityMutation)));
end
% Set a threshold for detecting mutations
threshold = 0.5;
detectedMutations = posteriorProbabilityMutation > threshold;
% Display results
disp(‘Posterior Probability of Mutation:’);
disp(posteriorProbabilityMutation);
disp(‘Detected Mutations:’);
disp(detectedMutations);
% Visualization
figure;
subplot(3, 1, 1);
bar(posteriorProbabilityMutation, ‘b’);
xlabel(‘Position’);
ylabel(‘Posterior Probability of Mutation’);
title(‘Bayesian Inference’);
grid on;
subplot(3, 1, 2);
plot(originalSequence, ‘bo’, ‘LineWidth’, 2);
hold on;
plot(mutatedSequence, ‘rx’, ‘LineWidth’, 2);
scatter(find(detectedMutations), ones(1, sum(detectedMutations)), ‘g’, ‘filled’);
legend(‘Original Sequence’, ‘Mutated Sequence’, ‘Detected Mutations’);
xlabel(‘Position’);
ylabel(‘Nucleotide’);
title(‘DNA Sequence and Mutations’);
grid on;
hold off;
subplot(3, 1, 3);
stem(detectedMutations, ‘r’, ‘LineWidth’, 2);
xlabel(‘Position’);
ylabel(‘Mutation Detected’);
title(‘Mutation Detection’);
grid on; Code is executing correctly but would like to have the original and the mutated strings on the plot
% Simulate DNA sequence evolution with mutations
sequenceLength = 50;
mutationRate = 0.02;
% Generate random DNA sequence
originalSequence = randsample([‘A’, ‘T’, ‘C’, ‘G’], sequenceLength, true);
% Introduce mutations
mutatedSequence = originalSequence;
mutationPositions = rand(1, sequenceLength) < mutationRate;
mutatedSequence(mutationPositions) = randsample(setdiff([‘A’, ‘T’, ‘C’, ‘G’], mutatedSequence(mutationPositions)), sum(mutationPositions), true);
% Display original and mutated sequences
disp(‘Original Sequence:’);
disp(originalSequence);
disp(‘Mutated Sequence:’);
disp(mutatedSequence);
% Bayesian Inference to detect mutations
priorProbabilityMutation = 0.01; % Prior probability of mutation
likelihoodMutation = mutationRate; % Likelihood of observing a mutation
% Bayes’ Theorem for each position
posteriorProbabilityMutation = zeros(1, sequenceLength);
for i = 1:sequenceLength
evidence = strcmp(originalSequence(i), mutatedSequence(i));
posteriorProbabilityMutation(i) = (likelihoodMutation * priorProbabilityMutation) / ((likelihoodMutation * priorProbabilityMutation) + (~evidence * (1 – priorProbabilityMutation)));
end
% Set a threshold for detecting mutations
threshold = 0.5;
detectedMutations = posteriorProbabilityMutation > threshold;
% Display results
disp(‘Posterior Probability of Mutation:’);
disp(posteriorProbabilityMutation);
disp(‘Detected Mutations:’);
disp(detectedMutations);
% Visualization
figure;
subplot(3, 1, 1);
bar(posteriorProbabilityMutation, ‘b’);
xlabel(‘Position’);
ylabel(‘Posterior Probability of Mutation’);
title(‘Bayesian Inference’);
grid on;
subplot(3, 1, 2);
plot(originalSequence, ‘bo’, ‘LineWidth’, 2);
hold on;
plot(mutatedSequence, ‘rx’, ‘LineWidth’, 2);
scatter(find(detectedMutations), ones(1, sum(detectedMutations)), ‘g’, ‘filled’);
legend(‘Original Sequence’, ‘Mutated Sequence’, ‘Detected Mutations’);
xlabel(‘Position’);
ylabel(‘Nucleotide’);
title(‘DNA Sequence and Mutations’);
grid on;
hold off;
subplot(3, 1, 3);
stem(detectedMutations, ‘r’, ‘LineWidth’, 2);
xlabel(‘Position’);
ylabel(‘Mutation Detected’);
title(‘Mutation Detection’);
grid on; plot, plotting, string, values MATLAB Answers — New Questions
Write a MATLAB function that returns the square of a number.
funciton square = sqr (x)
square = x * x;
end
Is it correct ?funciton square = sqr (x)
square = x * x;
end
Is it correct ? funciton square = sqr (x)
square = x * x;
end
Is it correct ? sqr, homework MATLAB Answers — New Questions
should cost function be only one point?
should cost function be only one point?
assume I have numerous points to minimize, where I can change the values of these points. For example, I want to sweep from 90 to -90 with a step of 0.2 or 0.1, etc. Is it better to try an algorithm that attempts to minimize and maximize all points, or should I write a cost function and then try to work on it? Below, you can see a part of the code related to this.
or i must only have one point ????
be
first approach (alot of point)
and pls attention in teta3 here (where i like my func be max try to inverse it) in the end
(1./b(sumLenteta12+1:sumLenteta123))
function y = costy(x)
freq = 9*(10^9); %Freq
j = sqrt(-1); %Define Imaginary
l =(3*(10^8))/freq; %Lambda
k = (2*pi)/l; %Constant
d = 0.67*l; %Distant of each element
elementNumb = 34;
step = 0.5;
teta1 = ((-70) :step: (-40));
teta2 = ((-40) :step: (6));
teta3 = ((11) :step: (15));
teta4 = ((18) :step: (45));
teta5 = ((45) :step: (60));
tetat = [teta1,teta2,teta3,teta4,teta5];
lenteta1 = length(teta1);
sumLenteta12 = length(teta1) + length(teta2);
sumLenteta123 = length(teta3) + sumLenteta12;
sumLenteta1234 = sumLenteta123 + length(teta4);
g = zeros(elementNumb,length(tetat));
ww=90;
for h = 1:elementNumb
%%teta1
fo
g(h,aa) = g(h,aa)+(x(h) * ( exp(j*(h-1) * (k*d*sind(teta1(aa)+(ww*x(h+elementNumb))))))); %w W
end
%%teta2
for bb=(lenteta1+1):(sumLenteta12)
g(h,bb) =g(h,bb)+( x(h) * exp(j*(h-1) * (k*d*sind(teta2(bb-lenteta1)+(ww*x(h+elementNumb)))))); %with W
end
%%teta3
for cc = (sumLenteta12+1):(length(teta3)+sumLenteta12)
g(h,cc) = g(h,cc)+ (x(h) * exp(j*(h-1) * (k*d*sind(teta3(cc-sumLenteta12)…
+(ww*x(h+elementNumb)))))); %w W
end
%%teta4
for dd = (sumLenteta123+1):(sumLenteta123+length(teta4))
g(h,dd) = g(h,dd)+( x(h) * exp(j*(h-1) * (k*d*sind(teta4(dd-(sumLenteta123))…
+(ww*x(h+elementNumb)))))); %w W
end
%%teta5
for ee = (sumLenteta1234+1):(sumLenteta1234+length(teta5))
g(h,ee) = g(h,ee)+( x(h) * exp(j*(h-1) * (k*d*sind(teta5(ee-(sumLenteta1234))…
+(ww*x(h+elementNumb)))))); %w W
end
% disp([x(1),x(2),x(3),x(35),x(36),x(50)]);
end
%for weighting
w1 = 0;
w2 = 0;
w3 = 0;
w4 = 0;
w5 = 0;
b = abs(sum(g));
% b=b/max(b);
% b=20*log10(abs(b));
% for each point evaluate
b = [b(1:lenteta1)+w1,b(lenteta1+1:sumLenteta12)+w2,(1./b(sumLenteta12+1:sumLenteta123))+w3 …
,b(sumLenteta123+1:sumLenteta1234)+w4,b(sumLenteta1234+1:length(tetat))+w5];
y = b;
end
and one point here i get from each one max then try to minimize it
and attention here i add minus for max (teta3)
b3 = -max(b(sumLenteta12+1:sumLenteta123))+w3 ;
and this one wants more time
and formula which i use
function y = costy(x)
freq = 9*(10^9); %Freq
j = sqrt(-1); %Define Imaginary
l =(3*(10^8))/freq; %Lambda
k = (2*pi)/l; %Constant
d = 0.67*l; %Distant of each element
elementNumb = 34;
step = 0.5;
teta1 = ((-70) :step: (-40));
teta2 = ((-40) :step: (6));
teta3 = ((11) :step: (15));
teta4 = ((18) :step: (45));
teta5 = ((45) :step: (60));
tetat = [teta1,teta2,teta3,teta4,teta5];
lenteta1 = length(teta1);
sumLenteta12 = length(teta1) + length(teta2);
sumLenteta123 = length(teta3) + sumLenteta12;
sumLenteta1234 = sumLenteta123 + length(teta4);
g = zeros(elementNumb,length(tetat));
ww=90;
for h = 1:elementNumb
%%teta1
for aa = 1:length(teta1)
g(h,aa) = g(h,aa)+(x(h) * ( exp(j*(h-1) * (k*d*sind(teta1(aa)+(ww*x(h+elementNumb))))))); %w W
end
%%teta2
for bb=(lenteta1+1):(sumLenteta12)
g(h,bb) =g(h,bb)+( x(h) * exp(j*(h-1) * (k*d*sind(teta2(bb-lenteta1)+(ww*x(h+elementNumb)))))); %with W
end
%%teta3
for cc = (sumLenteta12+1):(length(teta3)+sumLenteta12)
g(h,cc) = g(h,cc)+ (x(h) * exp(j*(h-1) * (k*d*sind(teta3(cc-sumLenteta12)…
+(ww*x(h+elementNumb)))))); %w W
end
%%teta4
for dd = (sumLenteta123+1):(sumLenteta123+length(teta4))
g(h,dd) = g(h,dd)+( x(h) * exp(j*(h-1) * (k*d*sind(teta4(dd-(sumLenteta123))…
+(ww*x(h+elementNumb)))))); %w W
end
%%teta5
for ee = (sumLenteta1234+1):(sumLenteta1234+length(teta5))
g(h,ee) = g(h,ee)+( x(h) * exp(j*(h-1) * (k*d*sind(teta5(ee-(sumLenteta1234))…
+(ww*x(h+elementNumb)))))); %w W
end
% disp([x(1),x(2),x(3),x(35),x(36),x(50)]);
end
w1 = 0;
w2 = 0;
w3 = 0;
w4 = 0;
w5 = 0;
b = abs(sum(g));
% b=b/max(b);
% b=20*log10(abs(b));
%% for each point evaluate
% b = [b(1:lenteta1)+w1,b(lenteta1+1:sumLenteta12)+w2,(1./b(sumLenteta12+1:sumLenteta123))+w3 …
% ,b(sumLenteta123+1:sumLenteta1234)+w4,b(sumLenteta1234+1:length(tetat))+w5];
% y = b;
%% for one point evaluate
b1 = max(b(1:lenteta1))+w1;
b2 = max(b(lenteta1+1:sumLenteta12))+w2;
b3 = -max(b(sumLenteta12+1:sumLenteta123))+w3 ;
b4 = max(b(sumLenteta123+1:sumLenteta1234))+w4;
b5 = max(b(sumLenteta1234+1:length(tetat)))+w5;
totb=b1+b2+b3+b4+b5;
y = totb;
endshould cost function be only one point?
assume I have numerous points to minimize, where I can change the values of these points. For example, I want to sweep from 90 to -90 with a step of 0.2 or 0.1, etc. Is it better to try an algorithm that attempts to minimize and maximize all points, or should I write a cost function and then try to work on it? Below, you can see a part of the code related to this.
or i must only have one point ????
be
first approach (alot of point)
and pls attention in teta3 here (where i like my func be max try to inverse it) in the end
(1./b(sumLenteta12+1:sumLenteta123))
function y = costy(x)
freq = 9*(10^9); %Freq
j = sqrt(-1); %Define Imaginary
l =(3*(10^8))/freq; %Lambda
k = (2*pi)/l; %Constant
d = 0.67*l; %Distant of each element
elementNumb = 34;
step = 0.5;
teta1 = ((-70) :step: (-40));
teta2 = ((-40) :step: (6));
teta3 = ((11) :step: (15));
teta4 = ((18) :step: (45));
teta5 = ((45) :step: (60));
tetat = [teta1,teta2,teta3,teta4,teta5];
lenteta1 = length(teta1);
sumLenteta12 = length(teta1) + length(teta2);
sumLenteta123 = length(teta3) + sumLenteta12;
sumLenteta1234 = sumLenteta123 + length(teta4);
g = zeros(elementNumb,length(tetat));
ww=90;
for h = 1:elementNumb
%%teta1
fo
g(h,aa) = g(h,aa)+(x(h) * ( exp(j*(h-1) * (k*d*sind(teta1(aa)+(ww*x(h+elementNumb))))))); %w W
end
%%teta2
for bb=(lenteta1+1):(sumLenteta12)
g(h,bb) =g(h,bb)+( x(h) * exp(j*(h-1) * (k*d*sind(teta2(bb-lenteta1)+(ww*x(h+elementNumb)))))); %with W
end
%%teta3
for cc = (sumLenteta12+1):(length(teta3)+sumLenteta12)
g(h,cc) = g(h,cc)+ (x(h) * exp(j*(h-1) * (k*d*sind(teta3(cc-sumLenteta12)…
+(ww*x(h+elementNumb)))))); %w W
end
%%teta4
for dd = (sumLenteta123+1):(sumLenteta123+length(teta4))
g(h,dd) = g(h,dd)+( x(h) * exp(j*(h-1) * (k*d*sind(teta4(dd-(sumLenteta123))…
+(ww*x(h+elementNumb)))))); %w W
end
%%teta5
for ee = (sumLenteta1234+1):(sumLenteta1234+length(teta5))
g(h,ee) = g(h,ee)+( x(h) * exp(j*(h-1) * (k*d*sind(teta5(ee-(sumLenteta1234))…
+(ww*x(h+elementNumb)))))); %w W
end
% disp([x(1),x(2),x(3),x(35),x(36),x(50)]);
end
%for weighting
w1 = 0;
w2 = 0;
w3 = 0;
w4 = 0;
w5 = 0;
b = abs(sum(g));
% b=b/max(b);
% b=20*log10(abs(b));
% for each point evaluate
b = [b(1:lenteta1)+w1,b(lenteta1+1:sumLenteta12)+w2,(1./b(sumLenteta12+1:sumLenteta123))+w3 …
,b(sumLenteta123+1:sumLenteta1234)+w4,b(sumLenteta1234+1:length(tetat))+w5];
y = b;
end
and one point here i get from each one max then try to minimize it
and attention here i add minus for max (teta3)
b3 = -max(b(sumLenteta12+1:sumLenteta123))+w3 ;
and this one wants more time
and formula which i use
function y = costy(x)
freq = 9*(10^9); %Freq
j = sqrt(-1); %Define Imaginary
l =(3*(10^8))/freq; %Lambda
k = (2*pi)/l; %Constant
d = 0.67*l; %Distant of each element
elementNumb = 34;
step = 0.5;
teta1 = ((-70) :step: (-40));
teta2 = ((-40) :step: (6));
teta3 = ((11) :step: (15));
teta4 = ((18) :step: (45));
teta5 = ((45) :step: (60));
tetat = [teta1,teta2,teta3,teta4,teta5];
lenteta1 = length(teta1);
sumLenteta12 = length(teta1) + length(teta2);
sumLenteta123 = length(teta3) + sumLenteta12;
sumLenteta1234 = sumLenteta123 + length(teta4);
g = zeros(elementNumb,length(tetat));
ww=90;
for h = 1:elementNumb
%%teta1
for aa = 1:length(teta1)
g(h,aa) = g(h,aa)+(x(h) * ( exp(j*(h-1) * (k*d*sind(teta1(aa)+(ww*x(h+elementNumb))))))); %w W
end
%%teta2
for bb=(lenteta1+1):(sumLenteta12)
g(h,bb) =g(h,bb)+( x(h) * exp(j*(h-1) * (k*d*sind(teta2(bb-lenteta1)+(ww*x(h+elementNumb)))))); %with W
end
%%teta3
for cc = (sumLenteta12+1):(length(teta3)+sumLenteta12)
g(h,cc) = g(h,cc)+ (x(h) * exp(j*(h-1) * (k*d*sind(teta3(cc-sumLenteta12)…
+(ww*x(h+elementNumb)))))); %w W
end
%%teta4
for dd = (sumLenteta123+1):(sumLenteta123+length(teta4))
g(h,dd) = g(h,dd)+( x(h) * exp(j*(h-1) * (k*d*sind(teta4(dd-(sumLenteta123))…
+(ww*x(h+elementNumb)))))); %w W
end
%%teta5
for ee = (sumLenteta1234+1):(sumLenteta1234+length(teta5))
g(h,ee) = g(h,ee)+( x(h) * exp(j*(h-1) * (k*d*sind(teta5(ee-(sumLenteta1234))…
+(ww*x(h+elementNumb)))))); %w W
end
% disp([x(1),x(2),x(3),x(35),x(36),x(50)]);
end
w1 = 0;
w2 = 0;
w3 = 0;
w4 = 0;
w5 = 0;
b = abs(sum(g));
% b=b/max(b);
% b=20*log10(abs(b));
%% for each point evaluate
% b = [b(1:lenteta1)+w1,b(lenteta1+1:sumLenteta12)+w2,(1./b(sumLenteta12+1:sumLenteta123))+w3 …
% ,b(sumLenteta123+1:sumLenteta1234)+w4,b(sumLenteta1234+1:length(tetat))+w5];
% y = b;
%% for one point evaluate
b1 = max(b(1:lenteta1))+w1;
b2 = max(b(lenteta1+1:sumLenteta12))+w2;
b3 = -max(b(sumLenteta12+1:sumLenteta123))+w3 ;
b4 = max(b(sumLenteta123+1:sumLenteta1234))+w4;
b5 = max(b(sumLenteta1234+1:length(tetat)))+w5;
totb=b1+b2+b3+b4+b5;
y = totb;
end should cost function be only one point?
assume I have numerous points to minimize, where I can change the values of these points. For example, I want to sweep from 90 to -90 with a step of 0.2 or 0.1, etc. Is it better to try an algorithm that attempts to minimize and maximize all points, or should I write a cost function and then try to work on it? Below, you can see a part of the code related to this.
or i must only have one point ????
be
first approach (alot of point)
and pls attention in teta3 here (where i like my func be max try to inverse it) in the end
(1./b(sumLenteta12+1:sumLenteta123))
function y = costy(x)
freq = 9*(10^9); %Freq
j = sqrt(-1); %Define Imaginary
l =(3*(10^8))/freq; %Lambda
k = (2*pi)/l; %Constant
d = 0.67*l; %Distant of each element
elementNumb = 34;
step = 0.5;
teta1 = ((-70) :step: (-40));
teta2 = ((-40) :step: (6));
teta3 = ((11) :step: (15));
teta4 = ((18) :step: (45));
teta5 = ((45) :step: (60));
tetat = [teta1,teta2,teta3,teta4,teta5];
lenteta1 = length(teta1);
sumLenteta12 = length(teta1) + length(teta2);
sumLenteta123 = length(teta3) + sumLenteta12;
sumLenteta1234 = sumLenteta123 + length(teta4);
g = zeros(elementNumb,length(tetat));
ww=90;
for h = 1:elementNumb
%%teta1
fo
g(h,aa) = g(h,aa)+(x(h) * ( exp(j*(h-1) * (k*d*sind(teta1(aa)+(ww*x(h+elementNumb))))))); %w W
end
%%teta2
for bb=(lenteta1+1):(sumLenteta12)
g(h,bb) =g(h,bb)+( x(h) * exp(j*(h-1) * (k*d*sind(teta2(bb-lenteta1)+(ww*x(h+elementNumb)))))); %with W
end
%%teta3
for cc = (sumLenteta12+1):(length(teta3)+sumLenteta12)
g(h,cc) = g(h,cc)+ (x(h) * exp(j*(h-1) * (k*d*sind(teta3(cc-sumLenteta12)…
+(ww*x(h+elementNumb)))))); %w W
end
%%teta4
for dd = (sumLenteta123+1):(sumLenteta123+length(teta4))
g(h,dd) = g(h,dd)+( x(h) * exp(j*(h-1) * (k*d*sind(teta4(dd-(sumLenteta123))…
+(ww*x(h+elementNumb)))))); %w W
end
%%teta5
for ee = (sumLenteta1234+1):(sumLenteta1234+length(teta5))
g(h,ee) = g(h,ee)+( x(h) * exp(j*(h-1) * (k*d*sind(teta5(ee-(sumLenteta1234))…
+(ww*x(h+elementNumb)))))); %w W
end
% disp([x(1),x(2),x(3),x(35),x(36),x(50)]);
end
%for weighting
w1 = 0;
w2 = 0;
w3 = 0;
w4 = 0;
w5 = 0;
b = abs(sum(g));
% b=b/max(b);
% b=20*log10(abs(b));
% for each point evaluate
b = [b(1:lenteta1)+w1,b(lenteta1+1:sumLenteta12)+w2,(1./b(sumLenteta12+1:sumLenteta123))+w3 …
,b(sumLenteta123+1:sumLenteta1234)+w4,b(sumLenteta1234+1:length(tetat))+w5];
y = b;
end
and one point here i get from each one max then try to minimize it
and attention here i add minus for max (teta3)
b3 = -max(b(sumLenteta12+1:sumLenteta123))+w3 ;
and this one wants more time
and formula which i use
function y = costy(x)
freq = 9*(10^9); %Freq
j = sqrt(-1); %Define Imaginary
l =(3*(10^8))/freq; %Lambda
k = (2*pi)/l; %Constant
d = 0.67*l; %Distant of each element
elementNumb = 34;
step = 0.5;
teta1 = ((-70) :step: (-40));
teta2 = ((-40) :step: (6));
teta3 = ((11) :step: (15));
teta4 = ((18) :step: (45));
teta5 = ((45) :step: (60));
tetat = [teta1,teta2,teta3,teta4,teta5];
lenteta1 = length(teta1);
sumLenteta12 = length(teta1) + length(teta2);
sumLenteta123 = length(teta3) + sumLenteta12;
sumLenteta1234 = sumLenteta123 + length(teta4);
g = zeros(elementNumb,length(tetat));
ww=90;
for h = 1:elementNumb
%%teta1
for aa = 1:length(teta1)
g(h,aa) = g(h,aa)+(x(h) * ( exp(j*(h-1) * (k*d*sind(teta1(aa)+(ww*x(h+elementNumb))))))); %w W
end
%%teta2
for bb=(lenteta1+1):(sumLenteta12)
g(h,bb) =g(h,bb)+( x(h) * exp(j*(h-1) * (k*d*sind(teta2(bb-lenteta1)+(ww*x(h+elementNumb)))))); %with W
end
%%teta3
for cc = (sumLenteta12+1):(length(teta3)+sumLenteta12)
g(h,cc) = g(h,cc)+ (x(h) * exp(j*(h-1) * (k*d*sind(teta3(cc-sumLenteta12)…
+(ww*x(h+elementNumb)))))); %w W
end
%%teta4
for dd = (sumLenteta123+1):(sumLenteta123+length(teta4))
g(h,dd) = g(h,dd)+( x(h) * exp(j*(h-1) * (k*d*sind(teta4(dd-(sumLenteta123))…
+(ww*x(h+elementNumb)))))); %w W
end
%%teta5
for ee = (sumLenteta1234+1):(sumLenteta1234+length(teta5))
g(h,ee) = g(h,ee)+( x(h) * exp(j*(h-1) * (k*d*sind(teta5(ee-(sumLenteta1234))…
+(ww*x(h+elementNumb)))))); %w W
end
% disp([x(1),x(2),x(3),x(35),x(36),x(50)]);
end
w1 = 0;
w2 = 0;
w3 = 0;
w4 = 0;
w5 = 0;
b = abs(sum(g));
% b=b/max(b);
% b=20*log10(abs(b));
%% for each point evaluate
% b = [b(1:lenteta1)+w1,b(lenteta1+1:sumLenteta12)+w2,(1./b(sumLenteta12+1:sumLenteta123))+w3 …
% ,b(sumLenteta123+1:sumLenteta1234)+w4,b(sumLenteta1234+1:length(tetat))+w5];
% y = b;
%% for one point evaluate
b1 = max(b(1:lenteta1))+w1;
b2 = max(b(lenteta1+1:sumLenteta12))+w2;
b3 = -max(b(sumLenteta12+1:sumLenteta123))+w3 ;
b4 = max(b(sumLenteta123+1:sumLenteta1234))+w4;
b5 = max(b(sumLenteta1234+1:length(tetat)))+w5;
totb=b1+b2+b3+b4+b5;
y = totb;
end optimization, goal MATLAB Answers — New Questions
Source code for Heart Disease Prediction
Need a code for Heart Disease PredictionNeed a code for Heart Disease Prediction Need a code for Heart Disease Prediction source code MATLAB Answers — New Questions
How to find out area under the curved shape of the attached figure?
Post Content Post Content image processing, thresholding MATLAB Answers — New Questions
In App Designer,How to hide the title ,as shown in the picture
Post Content Post Content appdesigner MATLAB Answers — New Questions
Multi-Agent Reinforcement learning
I have a game similar to poker (but different) coded up in Matlab where the game is one Matlab function and each player’s strategy is a different function I’ve written. I’d like to replace two of the players with reinforcement learning AI agents so the AI plays itself and hopefully optimizes. Is it possible to do this in Matlab or do I have to use Simulink? I’ve never used the reiinforcement learning tools in Matlab so any pointers are appreciated.I have a game similar to poker (but different) coded up in Matlab where the game is one Matlab function and each player’s strategy is a different function I’ve written. I’d like to replace two of the players with reinforcement learning AI agents so the AI plays itself and hopefully optimizes. Is it possible to do this in Matlab or do I have to use Simulink? I’ve never used the reiinforcement learning tools in Matlab so any pointers are appreciated. I have a game similar to poker (but different) coded up in Matlab where the game is one Matlab function and each player’s strategy is a different function I’ve written. I’d like to replace two of the players with reinforcement learning AI agents so the AI plays itself and hopefully optimizes. Is it possible to do this in Matlab or do I have to use Simulink? I’ve never used the reiinforcement learning tools in Matlab so any pointers are appreciated. reinforcement learning, ai games MATLAB Answers — New Questions
Writing tiff file with multi channel and slices
Hello,
I would like to make a tiff file with c=2, z=10, t=1. Input array is 4 dimension, [height, width, channel, slice]. Currently I am using the code below, however, the output tiff file becomes c=1, z=20, t=1. Can anybody help me to fix it?
function write3Dtiff_Slice(array, filename)
dims = size(array);
% Ensure the array has four dimensions
if length(dims) < 4
dims(end+1:4) = 1;
end
% Set data type specific fields
if isa(array, ‘single’)
bitsPerSample = 32;
sampleFormat = Tiff.SampleFormat.IEEEFP;
elseif isa(array, ‘uint16’)
bitsPerSample = 16;
sampleFormat = Tiff.SampleFormat.UInt;
elseif isa(array, ‘uint8’)
bitsPerSample = 8;
sampleFormat = Tiff.SampleFormat.UInt;
else
disp(‘Unsupported data type’);
return;
end
% Loop through slices
for s = 1:dims(4)
% Open TIFF file for each slice in append mode
outtiff = Tiff(filename, ‘a’);
% Loop through channels for the current slice
for c = 1:dims(3)
% Set tag structure for each channel of each slice
tagstruct.ImageLength = dims(1);
tagstruct.ImageWidth = dims(2);
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
tagstruct.SamplesPerPixel = 1;
tagstruct.BitsPerSample = bitsPerSample;
tagstruct.SampleFormat = sampleFormat;
% Set the tag for the current channel
outtiff.setTag(tagstruct);
% Write the channel data
outtiff.write(array(:,:,c,s));
% Create a new directory for the next channel unless it’s the last channel of the last slice
if c ~= dims(3) || s ~= dims(4)
outtiff.writeDirectory();
end
end
% Close the file for the current slice
outtiff.close();
end
endHello,
I would like to make a tiff file with c=2, z=10, t=1. Input array is 4 dimension, [height, width, channel, slice]. Currently I am using the code below, however, the output tiff file becomes c=1, z=20, t=1. Can anybody help me to fix it?
function write3Dtiff_Slice(array, filename)
dims = size(array);
% Ensure the array has four dimensions
if length(dims) < 4
dims(end+1:4) = 1;
end
% Set data type specific fields
if isa(array, ‘single’)
bitsPerSample = 32;
sampleFormat = Tiff.SampleFormat.IEEEFP;
elseif isa(array, ‘uint16’)
bitsPerSample = 16;
sampleFormat = Tiff.SampleFormat.UInt;
elseif isa(array, ‘uint8’)
bitsPerSample = 8;
sampleFormat = Tiff.SampleFormat.UInt;
else
disp(‘Unsupported data type’);
return;
end
% Loop through slices
for s = 1:dims(4)
% Open TIFF file for each slice in append mode
outtiff = Tiff(filename, ‘a’);
% Loop through channels for the current slice
for c = 1:dims(3)
% Set tag structure for each channel of each slice
tagstruct.ImageLength = dims(1);
tagstruct.ImageWidth = dims(2);
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
tagstruct.SamplesPerPixel = 1;
tagstruct.BitsPerSample = bitsPerSample;
tagstruct.SampleFormat = sampleFormat;
% Set the tag for the current channel
outtiff.setTag(tagstruct);
% Write the channel data
outtiff.write(array(:,:,c,s));
% Create a new directory for the next channel unless it’s the last channel of the last slice
if c ~= dims(3) || s ~= dims(4)
outtiff.writeDirectory();
end
end
% Close the file for the current slice
outtiff.close();
end
end Hello,
I would like to make a tiff file with c=2, z=10, t=1. Input array is 4 dimension, [height, width, channel, slice]. Currently I am using the code below, however, the output tiff file becomes c=1, z=20, t=1. Can anybody help me to fix it?
function write3Dtiff_Slice(array, filename)
dims = size(array);
% Ensure the array has four dimensions
if length(dims) < 4
dims(end+1:4) = 1;
end
% Set data type specific fields
if isa(array, ‘single’)
bitsPerSample = 32;
sampleFormat = Tiff.SampleFormat.IEEEFP;
elseif isa(array, ‘uint16’)
bitsPerSample = 16;
sampleFormat = Tiff.SampleFormat.UInt;
elseif isa(array, ‘uint8’)
bitsPerSample = 8;
sampleFormat = Tiff.SampleFormat.UInt;
else
disp(‘Unsupported data type’);
return;
end
% Loop through slices
for s = 1:dims(4)
% Open TIFF file for each slice in append mode
outtiff = Tiff(filename, ‘a’);
% Loop through channels for the current slice
for c = 1:dims(3)
% Set tag structure for each channel of each slice
tagstruct.ImageLength = dims(1);
tagstruct.ImageWidth = dims(2);
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
tagstruct.SamplesPerPixel = 1;
tagstruct.BitsPerSample = bitsPerSample;
tagstruct.SampleFormat = sampleFormat;
% Set the tag for the current channel
outtiff.setTag(tagstruct);
% Write the channel data
outtiff.write(array(:,:,c,s));
% Create a new directory for the next channel unless it’s the last channel of the last slice
if c ~= dims(3) || s ~= dims(4)
outtiff.writeDirectory();
end
end
% Close the file for the current slice
outtiff.close();
end
end tif, channel, slice MATLAB Answers — New Questions