Tag Archives: matlab
Best practice: CWT image generating for Deep Learning images
Hi,
I am looking some advice/best practice for genrating, formating and saving CWT images.
The task: I have ~5000 hours of EEG data recorded with lables at each thirty second interval. I would like to generate the CWT image of each 30 second window and save it. The image, should be devoide of a border, tics, axis lables and titles (i.e. just the spectogram image).
The Problem: I can generate an image with cwt(sig,fs), which is square, however includes all the extra bits I don’t want, like borders:
load mtlb
w = cwt(mtlb);
cwt(mtlb,"bump",Fs)
I could extract the image out with a handle and save that way:
load mtlb
w = cwt(mtlb);
fig = cwt(mtlb,"bump",Fs); % Hide the output as it’s quite long.
However, it quicly becomes apparent that the image data is not square, but rectangular.
load mtlb
w = cwt(mtlb);
fig = cwt(mtlb,"bump",Fs);
imshow(abs(fig)) % here’s the same image in grayscale.
While I understand that the image is fundamentally rectangular, the skeewed aspect ratio becomes an unknown when ingested by a DL algoritum, to that end I would like to have all my images processed and "squared up" before being ingested. I wanted to know if anyone had any suggestions as to the best way to generate these CWT images in a manner that is easily ingested by DL networks, not disimilar to this paper, however the detail are light.Hi,
I am looking some advice/best practice for genrating, formating and saving CWT images.
The task: I have ~5000 hours of EEG data recorded with lables at each thirty second interval. I would like to generate the CWT image of each 30 second window and save it. The image, should be devoide of a border, tics, axis lables and titles (i.e. just the spectogram image).
The Problem: I can generate an image with cwt(sig,fs), which is square, however includes all the extra bits I don’t want, like borders:
load mtlb
w = cwt(mtlb);
cwt(mtlb,"bump",Fs)
I could extract the image out with a handle and save that way:
load mtlb
w = cwt(mtlb);
fig = cwt(mtlb,"bump",Fs); % Hide the output as it’s quite long.
However, it quicly becomes apparent that the image data is not square, but rectangular.
load mtlb
w = cwt(mtlb);
fig = cwt(mtlb,"bump",Fs);
imshow(abs(fig)) % here’s the same image in grayscale.
While I understand that the image is fundamentally rectangular, the skeewed aspect ratio becomes an unknown when ingested by a DL algoritum, to that end I would like to have all my images processed and "squared up" before being ingested. I wanted to know if anyone had any suggestions as to the best way to generate these CWT images in a manner that is easily ingested by DL networks, not disimilar to this paper, however the detail are light. Hi,
I am looking some advice/best practice for genrating, formating and saving CWT images.
The task: I have ~5000 hours of EEG data recorded with lables at each thirty second interval. I would like to generate the CWT image of each 30 second window and save it. The image, should be devoide of a border, tics, axis lables and titles (i.e. just the spectogram image).
The Problem: I can generate an image with cwt(sig,fs), which is square, however includes all the extra bits I don’t want, like borders:
load mtlb
w = cwt(mtlb);
cwt(mtlb,"bump",Fs)
I could extract the image out with a handle and save that way:
load mtlb
w = cwt(mtlb);
fig = cwt(mtlb,"bump",Fs); % Hide the output as it’s quite long.
However, it quicly becomes apparent that the image data is not square, but rectangular.
load mtlb
w = cwt(mtlb);
fig = cwt(mtlb,"bump",Fs);
imshow(abs(fig)) % here’s the same image in grayscale.
While I understand that the image is fundamentally rectangular, the skeewed aspect ratio becomes an unknown when ingested by a DL algoritum, to that end I would like to have all my images processed and "squared up" before being ingested. I wanted to know if anyone had any suggestions as to the best way to generate these CWT images in a manner that is easily ingested by DL networks, not disimilar to this paper, however the detail are light. image processing, image analysis, cwt MATLAB Answers — New Questions
Random Binary Bits Generation
Working with NIST Test Suite which have 16 Test to test Randomness of data,
My Problem is I want such random binary bits of length 10^6, which have P-Value over .95 for all the NIST Test, I’ve spend almost a week trying different Stream Ciphers, RNG PRNG, different combination of these, nothing works for me is it possible to generate these numbers consistantly with desired P-Values.
Thank YouWorking with NIST Test Suite which have 16 Test to test Randomness of data,
My Problem is I want such random binary bits of length 10^6, which have P-Value over .95 for all the NIST Test, I’ve spend almost a week trying different Stream Ciphers, RNG PRNG, different combination of these, nothing works for me is it possible to generate these numbers consistantly with desired P-Values.
Thank You Working with NIST Test Suite which have 16 Test to test Randomness of data,
My Problem is I want such random binary bits of length 10^6, which have P-Value over .95 for all the NIST Test, I’ve spend almost a week trying different Stream Ciphers, RNG PRNG, different combination of these, nothing works for me is it possible to generate these numbers consistantly with desired P-Values.
Thank You nist, random number generator, cryptography, binary MATLAB Answers — New Questions
lqr controller tuning way
while controlling two variables using lqr controller not able to properly tune Q and R . what is best way to tune themwhile controlling two variables using lqr controller not able to properly tune Q and R . what is best way to tune them while controlling two variables using lqr controller not able to properly tune Q and R . what is best way to tune them lqr controller MATLAB Answers — New Questions
Greek characters on plot being truncated
Hello all!
My problem is that my greek characters are being truncated when I try to use them in x- & y-axis labels. For example, the code:
ylabel(‘phi [cm^2]’,’FontSize’,14)
produces a y-axis label that looks like a lower-case _phi_ that has been cut in half. Has anyone encountered this problem before, or can anyone tell me what I’m doing wrong? Thanks!
*_Update_*: I am using MATLAB R2010a (7.10.0.499) on Mac OS X Lion (10.7.2).Hello all!
My problem is that my greek characters are being truncated when I try to use them in x- & y-axis labels. For example, the code:
ylabel(‘phi [cm^2]’,’FontSize’,14)
produces a y-axis label that looks like a lower-case _phi_ that has been cut in half. Has anyone encountered this problem before, or can anyone tell me what I’m doing wrong? Thanks!
*_Update_*: I am using MATLAB R2010a (7.10.0.499) on Mac OS X Lion (10.7.2). Hello all!
My problem is that my greek characters are being truncated when I try to use them in x- & y-axis labels. For example, the code:
ylabel(‘phi [cm^2]’,’FontSize’,14)
produces a y-axis label that looks like a lower-case _phi_ that has been cut in half. Has anyone encountered this problem before, or can anyone tell me what I’m doing wrong? Thanks!
*_Update_*: I am using MATLAB R2010a (7.10.0.499) on Mac OS X Lion (10.7.2). greek characters, plotting MATLAB Answers — New Questions
How to implement kriging in Matlab?
I need to perform kriging in Matlab based on three borehole samples.
Numbers for soil layers indicate depth from ground zero, boreholes – position on model.
The outcome should look something like this (already done that in Zsoil):
Any ideas how to perform this?I need to perform kriging in Matlab based on three borehole samples.
Numbers for soil layers indicate depth from ground zero, boreholes – position on model.
The outcome should look something like this (already done that in Zsoil):
Any ideas how to perform this? I need to perform kriging in Matlab based on three borehole samples.
Numbers for soil layers indicate depth from ground zero, boreholes – position on model.
The outcome should look something like this (already done that in Zsoil):
Any ideas how to perform this? kriging, samples, regression MATLAB Answers — New Questions
Why do I see the message “WARNING: The mjsscript detected that the number of processes allowed is limited by ulimit” when starting the mjs service on Linux?
Why do I see the message "WARNING: The mjs script detected that the number of processes allowed is limited by ulimit" when starting the mjs service on Linux?Why do I see the message "WARNING: The mjs script detected that the number of processes allowed is limited by ulimit" when starting the mjs service on Linux? Why do I see the message "WARNING: The mjs script detected that the number of processes allowed is limited by ulimit" when starting the mjs service on Linux? MATLAB Answers — New Questions
Ask for help to solve the question.
write a script to input an integer number between 0 and 255, and output the number to the screen between the characters ‘< ‘ and ‘ > ‘ . This input and display operation should be repeated 10 times. After the 10th iteration the script should save all the input numbers to a text file in a human readable form.
I have no idea to do it.write a script to input an integer number between 0 and 255, and output the number to the screen between the characters ‘< ‘ and ‘ > ‘ . This input and display operation should be repeated 10 times. After the 10th iteration the script should save all the input numbers to a text file in a human readable form.
I have no idea to do it. write a script to input an integer number between 0 and 255, and output the number to the screen between the characters ‘< ‘ and ‘ > ‘ . This input and display operation should be repeated 10 times. After the 10th iteration the script should save all the input numbers to a text file in a human readable form.
I have no idea to do it. MATLAB Answers — New Questions
How do I restore my Simulink Favourite Commands?
Hello,
my Matlab did not start so I followed the advice to rename the preference folder and create a new, blank reference folder as described here:
https://www.mathworks.com/matlabcentral/answers/97167-why-will-matlab-not-start-up-properly-on-my-windows-based-system
Unfortunately, this got rid of my favourite commands both in Matlab and in Simulink. However, I was able to restore the Matlab Favourite Commands by following this guideline:
https://www.mathworks.com/matlabcentral/answers/99625-how-do-i-regenerate-my-matlab-preferences
But how exactly do I restore the Simulink Favourite commands? I didn’t delete any preferences, they’re just in a different folder now. I think, I should be able to restore them.
Thanks!Hello,
my Matlab did not start so I followed the advice to rename the preference folder and create a new, blank reference folder as described here:
https://www.mathworks.com/matlabcentral/answers/97167-why-will-matlab-not-start-up-properly-on-my-windows-based-system
Unfortunately, this got rid of my favourite commands both in Matlab and in Simulink. However, I was able to restore the Matlab Favourite Commands by following this guideline:
https://www.mathworks.com/matlabcentral/answers/99625-how-do-i-regenerate-my-matlab-preferences
But how exactly do I restore the Simulink Favourite commands? I didn’t delete any preferences, they’re just in a different folder now. I think, I should be able to restore them.
Thanks! Hello,
my Matlab did not start so I followed the advice to rename the preference folder and create a new, blank reference folder as described here:
https://www.mathworks.com/matlabcentral/answers/97167-why-will-matlab-not-start-up-properly-on-my-windows-based-system
Unfortunately, this got rid of my favourite commands both in Matlab and in Simulink. However, I was able to restore the Matlab Favourite Commands by following this guideline:
https://www.mathworks.com/matlabcentral/answers/99625-how-do-i-regenerate-my-matlab-preferences
But how exactly do I restore the Simulink Favourite commands? I didn’t delete any preferences, they’re just in a different folder now. I think, I should be able to restore them.
Thanks! simulink MATLAB Answers — New Questions
Feedback diversity system in Wireless communication
Can anyone tell a way to create a simulation to depict the feedback diversity system wirelesscommunication using matlab 2023Can anyone tell a way to create a simulation to depict the feedback diversity system wirelesscommunication using matlab 2023 Can anyone tell a way to create a simulation to depict the feedback diversity system wirelesscommunication using matlab 2023 wireless MATLAB Answers — New Questions
une méthode pour installer matlab
Bonjour tout le monde
j’espère que vous allez bien,
s’il vous plait de me donner une solution, à chaque fois que je l’installe il me donne le message suivant " please specify the location of a valid matlab R2018a installation "
prière de me répondre et merci d’avanceBonjour tout le monde
j’espère que vous allez bien,
s’il vous plait de me donner une solution, à chaque fois que je l’installe il me donne le message suivant " please specify the location of a valid matlab R2018a installation "
prière de me répondre et merci d’avance Bonjour tout le monde
j’espère que vous allez bien,
s’il vous plait de me donner une solution, à chaque fois que je l’installe il me donne le message suivant " please specify the location of a valid matlab R2018a installation "
prière de me répondre et merci d’avance installation MATLAB Answers — New Questions
A problem about comm.RicianChannel
Hello,everyone.
Recently I am working on a project of OFDM simulation. I want to use comm.RicianChannel object for the fading channel. After I read the docuument, I am confused that why the output signal of the object have the same length with the input signal? I mean that if we have a fading channel response, the conv result will make the signal longer(for delay reason), is that right?Hello,everyone.
Recently I am working on a project of OFDM simulation. I want to use comm.RicianChannel object for the fading channel. After I read the docuument, I am confused that why the output signal of the object have the same length with the input signal? I mean that if we have a fading channel response, the conv result will make the signal longer(for delay reason), is that right? Hello,everyone.
Recently I am working on a project of OFDM simulation. I want to use comm.RicianChannel object for the fading channel. After I read the docuument, I am confused that why the output signal of the object have the same length with the input signal? I mean that if we have a fading channel response, the conv result will make the signal longer(for delay reason), is that right? fading channel MATLAB Answers — New Questions
Problem with evaluateObjectDetection function
Hello, everyone,
I would like help with the function in question…
I attach the tables groundTruthData and detectionResults.
thanks
CODE:
% Evaluate object detection results
metrics = evaluateObjectDetection(detectionResultsTbl, groundTruthDataTbl);
% Extract precision and recall for a specific class ID (e.g. classID = 1)
classID = 1;
precision = metrics.ClassMetrics.Precision{classID};
recall = metrics.ClassMetrics.Recall{classID};
% Plot the precision-recall curve
figure
plot(recall, precision);
xlabel("Recall");
ylabel("Precision");
grid on;
title(sprintf("Average Precision = %.2f", metrics.ClassMetrics.mAP(classID)));
ERROR:
Error using evaluateObjectDetection>iFindOutputIdxsFromDS
Missing data in detectionResults. Unable to find Label data in detectionResults.
Error in evaluateObjectDetection (line 27)
predOutIdxs = iFindOutputIdxsFromDS(dsResultsCopy, 3, "detectionResults");
Error in untitled2 (line 306)
metrics = evaluateObjectDetection(detectionResultsTbl, groundTruthDataTbl);Hello, everyone,
I would like help with the function in question…
I attach the tables groundTruthData and detectionResults.
thanks
CODE:
% Evaluate object detection results
metrics = evaluateObjectDetection(detectionResultsTbl, groundTruthDataTbl);
% Extract precision and recall for a specific class ID (e.g. classID = 1)
classID = 1;
precision = metrics.ClassMetrics.Precision{classID};
recall = metrics.ClassMetrics.Recall{classID};
% Plot the precision-recall curve
figure
plot(recall, precision);
xlabel("Recall");
ylabel("Precision");
grid on;
title(sprintf("Average Precision = %.2f", metrics.ClassMetrics.mAP(classID)));
ERROR:
Error using evaluateObjectDetection>iFindOutputIdxsFromDS
Missing data in detectionResults. Unable to find Label data in detectionResults.
Error in evaluateObjectDetection (line 27)
predOutIdxs = iFindOutputIdxsFromDS(dsResultsCopy, 3, "detectionResults");
Error in untitled2 (line 306)
metrics = evaluateObjectDetection(detectionResultsTbl, groundTruthDataTbl); Hello, everyone,
I would like help with the function in question…
I attach the tables groundTruthData and detectionResults.
thanks
CODE:
% Evaluate object detection results
metrics = evaluateObjectDetection(detectionResultsTbl, groundTruthDataTbl);
% Extract precision and recall for a specific class ID (e.g. classID = 1)
classID = 1;
precision = metrics.ClassMetrics.Precision{classID};
recall = metrics.ClassMetrics.Recall{classID};
% Plot the precision-recall curve
figure
plot(recall, precision);
xlabel("Recall");
ylabel("Precision");
grid on;
title(sprintf("Average Precision = %.2f", metrics.ClassMetrics.mAP(classID)));
ERROR:
Error using evaluateObjectDetection>iFindOutputIdxsFromDS
Missing data in detectionResults. Unable to find Label data in detectionResults.
Error in evaluateObjectDetection (line 27)
predOutIdxs = iFindOutputIdxsFromDS(dsResultsCopy, 3, "detectionResults");
Error in untitled2 (line 306)
metrics = evaluateObjectDetection(detectionResultsTbl, groundTruthDataTbl); plot MATLAB Answers — New Questions
What is the syntax to share support vectors among multiple regression SVMs?
I am fitting 64 support vector machines to accomplish a regression task on 64-dimensional targets. At the moment, I am simply iterating through each regression and saving the individually-fit models in a cell array. I find that each model has ~2000 support vectors and would like to reduce the storage the models require by identifying which support vectors are shared among regressors and having the models point to the shared support vectors rather than duplicate them. Is there a wrapper function that can identify and consolidate shared support vectors as the models train, or must I implement this manually? I am afraid I cannot simply install Python to use sklearn.I am fitting 64 support vector machines to accomplish a regression task on 64-dimensional targets. At the moment, I am simply iterating through each regression and saving the individually-fit models in a cell array. I find that each model has ~2000 support vectors and would like to reduce the storage the models require by identifying which support vectors are shared among regressors and having the models point to the shared support vectors rather than duplicate them. Is there a wrapper function that can identify and consolidate shared support vectors as the models train, or must I implement this manually? I am afraid I cannot simply install Python to use sklearn. I am fitting 64 support vector machines to accomplish a regression task on 64-dimensional targets. At the moment, I am simply iterating through each regression and saving the individually-fit models in a cell array. I find that each model has ~2000 support vectors and would like to reduce the storage the models require by identifying which support vectors are shared among regressors and having the models point to the shared support vectors rather than duplicate them. Is there a wrapper function that can identify and consolidate shared support vectors as the models train, or must I implement this manually? I am afraid I cannot simply install Python to use sklearn. machine learning, statistics, svm, regression MATLAB Answers — New Questions
Why do I receive the error message “Unable to rename file C:TempPolyspace1D78_150813568926D75C_18C1_208C.expanded into C:TempPolyspace1D78_150813568926D75C_18C1_208C” Exiting. System error Permission denied (acces: Permission denied)
In a Polyspace verification/analysis, I receive the following error message:
Verifying sources …
Verifying a.c (1/87)
Verifying b.c (2/87)
Verifying c.c (3/87)
*** Unable to rename file "C:TempPolyspace1D78_150813568926D75C_18C1_208C.expanded" into C:TempPolyspace1D78_150813568926D75C_18C1_208C". Exiting.System error Permission denied (acces: Permission denied)
Why am I receiving this error and how can I fix it?
In a Polyspace verification/analysis, I receive the following error message:
Verifying sources …
Verifying a.c (1/87)
Verifying b.c (2/87)
Verifying c.c (3/87)
*** Unable to rename file "C:TempPolyspace1D78_150813568926D75C_18C1_208C.expanded" into C:TempPolyspace1D78_150813568926D75C_18C1_208C". Exiting.System error Permission denied (acces: Permission denied)
Why am I receiving this error and how can I fix it?
In a Polyspace verification/analysis, I receive the following error message:
Verifying sources …
Verifying a.c (1/87)
Verifying b.c (2/87)
Verifying c.c (3/87)
*** Unable to rename file "C:TempPolyspace1D78_150813568926D75C_18C1_208C.expanded" into C:TempPolyspace1D78_150813568926D75C_18C1_208C". Exiting.System error Permission denied (acces: Permission denied)
Why am I receiving this error and how can I fix it?
MATLAB Answers — New Questions
How can i edit my code which works on r2014b version at work but not on my personal r2024a version?
I have an IAD code, number of lines long. It works great on the MATLAB r2014b version but on my r2024a version at home, i get an error of the following:
Running IAD on dataset 1
zsh:1: command not found: iad
Sample1_IAD.txt
Error using movefile
No matching files named ‘XXXXXX’ were found.
Error in IAD_Analyzer_WCV_04_11_23 (line 239)
movefile(iad_output_file,strcat([pwd, ‘results’]))
Please can someone well versed in MATLAB suggest what I should change in the code to address this error in the r2024a version? It seems to be a matter of changing file location or using a different cmd from ‘movefile’ etc but I’ve tried all I know to do with no success. Thank you, I appreciate any help.I have an IAD code, number of lines long. It works great on the MATLAB r2014b version but on my r2024a version at home, i get an error of the following:
Running IAD on dataset 1
zsh:1: command not found: iad
Sample1_IAD.txt
Error using movefile
No matching files named ‘XXXXXX’ were found.
Error in IAD_Analyzer_WCV_04_11_23 (line 239)
movefile(iad_output_file,strcat([pwd, ‘results’]))
Please can someone well versed in MATLAB suggest what I should change in the code to address this error in the r2024a version? It seems to be a matter of changing file location or using a different cmd from ‘movefile’ etc but I’ve tried all I know to do with no success. Thank you, I appreciate any help. I have an IAD code, number of lines long. It works great on the MATLAB r2014b version but on my r2024a version at home, i get an error of the following:
Running IAD on dataset 1
zsh:1: command not found: iad
Sample1_IAD.txt
Error using movefile
No matching files named ‘XXXXXX’ were found.
Error in IAD_Analyzer_WCV_04_11_23 (line 239)
movefile(iad_output_file,strcat([pwd, ‘results’]))
Please can someone well versed in MATLAB suggest what I should change in the code to address this error in the r2024a version? It seems to be a matter of changing file location or using a different cmd from ‘movefile’ etc but I’ve tried all I know to do with no success. Thank you, I appreciate any help. iad code, image processing MATLAB Answers — New Questions
How do I activate MATLAB or other MathWorks products without an internet connection?
How do I activate MATLAB and/or other MathWorks products on a computer that is not connected to the internet?How do I activate MATLAB and/or other MathWorks products on a computer that is not connected to the internet? How do I activate MATLAB and/or other MathWorks products on a computer that is not connected to the internet? MATLAB Answers — New Questions
Adding a Column to a Table
Hello everyone, I’ve just started out with Matlab for uni and am trying to add a column to a table. I ran into the following error message
Error using .
To assign to or create a variable in a table, the number of rows must match the height of the table.
My code is written below:
%Creates a table called ‘tab’ using the data in the coronavirus-cases.csv
%file.
tab = readtable("coronavirus-cases.csv");
%Creates a row of zeros with the same height as tab.
newTabCol = zeros(height(tab), 1);
%Adds the column and titles it "Seven Day Average".
tab.newTabCol = "Seven Day Average";
What confuses me is that the height of newTabCol matches tab. Both have 153772 rows:
I’m sure I’m missing something basic but any help would be appreciated.
Kind regards,
JohnHello everyone, I’ve just started out with Matlab for uni and am trying to add a column to a table. I ran into the following error message
Error using .
To assign to or create a variable in a table, the number of rows must match the height of the table.
My code is written below:
%Creates a table called ‘tab’ using the data in the coronavirus-cases.csv
%file.
tab = readtable("coronavirus-cases.csv");
%Creates a row of zeros with the same height as tab.
newTabCol = zeros(height(tab), 1);
%Adds the column and titles it "Seven Day Average".
tab.newTabCol = "Seven Day Average";
What confuses me is that the height of newTabCol matches tab. Both have 153772 rows:
I’m sure I’m missing something basic but any help would be appreciated.
Kind regards,
John Hello everyone, I’ve just started out with Matlab for uni and am trying to add a column to a table. I ran into the following error message
Error using .
To assign to or create a variable in a table, the number of rows must match the height of the table.
My code is written below:
%Creates a table called ‘tab’ using the data in the coronavirus-cases.csv
%file.
tab = readtable("coronavirus-cases.csv");
%Creates a row of zeros with the same height as tab.
newTabCol = zeros(height(tab), 1);
%Adds the column and titles it "Seven Day Average".
tab.newTabCol = "Seven Day Average";
What confuses me is that the height of newTabCol matches tab. Both have 153772 rows:
I’m sure I’m missing something basic but any help would be appreciated.
Kind regards,
John table, column, add, add column, height, zeros MATLAB Answers — New Questions
Mensaje constante de actualización Matlab Connector
Hola a todos. Estoy usando la versión R2024a de Matlab y cada 5 o 10 minutos me aparece el mensaje "You already have the most recent version of MATLAB Connector installed". Entiendo que esta buscando actualizaciones, pero no se porque lo hace constantemente. Estoy en Windows 11.
Muchas gracias por su ayudaHola a todos. Estoy usando la versión R2024a de Matlab y cada 5 o 10 minutos me aparece el mensaje "You already have the most recent version of MATLAB Connector installed". Entiendo que esta buscando actualizaciones, pero no se porque lo hace constantemente. Estoy en Windows 11.
Muchas gracias por su ayuda Hola a todos. Estoy usando la versión R2024a de Matlab y cada 5 o 10 minutos me aparece el mensaje "You already have the most recent version of MATLAB Connector installed". Entiendo que esta buscando actualizaciones, pero no se porque lo hace constantemente. Estoy en Windows 11.
Muchas gracias por su ayuda matlab connector MATLAB Answers — New Questions
Importing files in bulk chnages table columns to NaNs
I have the following code in which I want to replace the column 37 in a table. I want to swap the column of categorical values for a column of numerical values.
% Open file selection dialog and allow multiple selections
[file_list, path_n] = uigetfile(‘*.csv’, ‘Select CSV Files’, ‘Multiselect’, ‘on’);
% Check if any files were selected
if ischar(file_list)
% Convert single file string to cell array
file_list = {file_list};
end
% Initialize a cell array to store the modified tables
modifiedTables = cell(length(file_list), 1);
% Loop through each selected file
for k = 1:length(file_list)
% Construct the full file path
filePath = fullfile(path_n, file_list{k});
% Import the CSV file as a table
T = readtable(filePath);
% Check if the table has at least 37 columns
if width(T) >= 37
% Extract the ‘OrderNumber’ column (column 37) and convert it to a string array
orderNumberColumn = string(T{:, 37});
% Initialize the new column as a double array with the same size as the original column
newOrderNumberColumn = zeros(size(orderNumberColumn));
% Convert the string values to doubles
for i = 1:length(orderNumberColumn)
numValue = str2double(orderNumberColumn(i));
if isnan(numValue)
% If conversion fails (non-numeric value), set the value to 0
newOrderNumberColumn(i) = 0;
else
% Otherwise, use the numeric value
newOrderNumberColumn(i) = numValue;
end
end
% Update only the 37th column with the new double column
T.(T.Properties.VariableNames{37}) = newOrderNumberColumn;
end
% Store the modified table in the cell array
modifiedTables{k} = T;
end
% Display the number of tables processed
disp([‘Number of tables processed: ‘, num2str(length(modifiedTables))]);
Unfortunately, the other columns (for example column 35, 36,38 and 39) also become affected when importing the csv files in bulk and hence my new modified table now contains NaNs even though I would like to only modify the column 37 (see "modifiedtables").
When I import via the user interface (see "imported_by_hand") or when I use the code below(see "T") that doesnt seem to happen.
T_copy = T;
% Extract the ‘OrderNumber’ column (column 37) and convert it to a string array
orderNumberColumn = string(T_copy{:, 37});
% Initialize the new column as a double array with the same size as the original column
newOrderNumberColumn = zeros(size(orderNumberColumn));
% Convert the string values to doubles
for i = 1:length(orderNumberColumn)
numValue = str2double(orderNumberColumn(i));
if isnan(numValue)
% If conversion fails (non-numeric value), set the value to 0
newOrderNumberColumn(i) = 0;
else
% Otherwise, use the numeric value
newOrderNumberColumn(i) = numValue;
end
end
% Replace the 37th column with the new double column by creating a new table
% Get the table variable names
varNames = T_copy.Properties.VariableNames;
How can I keep this from happening when I import the data in bulk?
Thanks!I have the following code in which I want to replace the column 37 in a table. I want to swap the column of categorical values for a column of numerical values.
% Open file selection dialog and allow multiple selections
[file_list, path_n] = uigetfile(‘*.csv’, ‘Select CSV Files’, ‘Multiselect’, ‘on’);
% Check if any files were selected
if ischar(file_list)
% Convert single file string to cell array
file_list = {file_list};
end
% Initialize a cell array to store the modified tables
modifiedTables = cell(length(file_list), 1);
% Loop through each selected file
for k = 1:length(file_list)
% Construct the full file path
filePath = fullfile(path_n, file_list{k});
% Import the CSV file as a table
T = readtable(filePath);
% Check if the table has at least 37 columns
if width(T) >= 37
% Extract the ‘OrderNumber’ column (column 37) and convert it to a string array
orderNumberColumn = string(T{:, 37});
% Initialize the new column as a double array with the same size as the original column
newOrderNumberColumn = zeros(size(orderNumberColumn));
% Convert the string values to doubles
for i = 1:length(orderNumberColumn)
numValue = str2double(orderNumberColumn(i));
if isnan(numValue)
% If conversion fails (non-numeric value), set the value to 0
newOrderNumberColumn(i) = 0;
else
% Otherwise, use the numeric value
newOrderNumberColumn(i) = numValue;
end
end
% Update only the 37th column with the new double column
T.(T.Properties.VariableNames{37}) = newOrderNumberColumn;
end
% Store the modified table in the cell array
modifiedTables{k} = T;
end
% Display the number of tables processed
disp([‘Number of tables processed: ‘, num2str(length(modifiedTables))]);
Unfortunately, the other columns (for example column 35, 36,38 and 39) also become affected when importing the csv files in bulk and hence my new modified table now contains NaNs even though I would like to only modify the column 37 (see "modifiedtables").
When I import via the user interface (see "imported_by_hand") or when I use the code below(see "T") that doesnt seem to happen.
T_copy = T;
% Extract the ‘OrderNumber’ column (column 37) and convert it to a string array
orderNumberColumn = string(T_copy{:, 37});
% Initialize the new column as a double array with the same size as the original column
newOrderNumberColumn = zeros(size(orderNumberColumn));
% Convert the string values to doubles
for i = 1:length(orderNumberColumn)
numValue = str2double(orderNumberColumn(i));
if isnan(numValue)
% If conversion fails (non-numeric value), set the value to 0
newOrderNumberColumn(i) = 0;
else
% Otherwise, use the numeric value
newOrderNumberColumn(i) = numValue;
end
end
% Replace the 37th column with the new double column by creating a new table
% Get the table variable names
varNames = T_copy.Properties.VariableNames;
How can I keep this from happening when I import the data in bulk?
Thanks! I have the following code in which I want to replace the column 37 in a table. I want to swap the column of categorical values for a column of numerical values.
% Open file selection dialog and allow multiple selections
[file_list, path_n] = uigetfile(‘*.csv’, ‘Select CSV Files’, ‘Multiselect’, ‘on’);
% Check if any files were selected
if ischar(file_list)
% Convert single file string to cell array
file_list = {file_list};
end
% Initialize a cell array to store the modified tables
modifiedTables = cell(length(file_list), 1);
% Loop through each selected file
for k = 1:length(file_list)
% Construct the full file path
filePath = fullfile(path_n, file_list{k});
% Import the CSV file as a table
T = readtable(filePath);
% Check if the table has at least 37 columns
if width(T) >= 37
% Extract the ‘OrderNumber’ column (column 37) and convert it to a string array
orderNumberColumn = string(T{:, 37});
% Initialize the new column as a double array with the same size as the original column
newOrderNumberColumn = zeros(size(orderNumberColumn));
% Convert the string values to doubles
for i = 1:length(orderNumberColumn)
numValue = str2double(orderNumberColumn(i));
if isnan(numValue)
% If conversion fails (non-numeric value), set the value to 0
newOrderNumberColumn(i) = 0;
else
% Otherwise, use the numeric value
newOrderNumberColumn(i) = numValue;
end
end
% Update only the 37th column with the new double column
T.(T.Properties.VariableNames{37}) = newOrderNumberColumn;
end
% Store the modified table in the cell array
modifiedTables{k} = T;
end
% Display the number of tables processed
disp([‘Number of tables processed: ‘, num2str(length(modifiedTables))]);
Unfortunately, the other columns (for example column 35, 36,38 and 39) also become affected when importing the csv files in bulk and hence my new modified table now contains NaNs even though I would like to only modify the column 37 (see "modifiedtables").
When I import via the user interface (see "imported_by_hand") or when I use the code below(see "T") that doesnt seem to happen.
T_copy = T;
% Extract the ‘OrderNumber’ column (column 37) and convert it to a string array
orderNumberColumn = string(T_copy{:, 37});
% Initialize the new column as a double array with the same size as the original column
newOrderNumberColumn = zeros(size(orderNumberColumn));
% Convert the string values to doubles
for i = 1:length(orderNumberColumn)
numValue = str2double(orderNumberColumn(i));
if isnan(numValue)
% If conversion fails (non-numeric value), set the value to 0
newOrderNumberColumn(i) = 0;
else
% Otherwise, use the numeric value
newOrderNumberColumn(i) = numValue;
end
end
% Replace the 37th column with the new double column by creating a new table
% Get the table variable names
varNames = T_copy.Properties.VariableNames;
How can I keep this from happening when I import the data in bulk?
Thanks! categorical variable, table, convert, import MATLAB Answers — New Questions
Why did I get two different results in nonlinear programing problems
clear,clc
A = [1 4 5
4 2 6
5 6 3];
prob = optimproblem;
x = optimvar(‘x’,3);
con = sum(x.^2) == 1;
prob.Constraints.con = con;
prob.Objective = x’*A*x;
x0.x = zeros(3,1);
% x0.x = rand(3,1);
show(prob)
[sol,fval,flag,out] = solve(prob,x0)
sol.x
when the initial point is zeres(0),fval is 0,sol.x is [0;0;0].
but when it is rand(3,1),fval is -3.66.
I can’t understand this reasonclear,clc
A = [1 4 5
4 2 6
5 6 3];
prob = optimproblem;
x = optimvar(‘x’,3);
con = sum(x.^2) == 1;
prob.Constraints.con = con;
prob.Objective = x’*A*x;
x0.x = zeros(3,1);
% x0.x = rand(3,1);
show(prob)
[sol,fval,flag,out] = solve(prob,x0)
sol.x
when the initial point is zeres(0),fval is 0,sol.x is [0;0;0].
but when it is rand(3,1),fval is -3.66.
I can’t understand this reason clear,clc
A = [1 4 5
4 2 6
5 6 3];
prob = optimproblem;
x = optimvar(‘x’,3);
con = sum(x.^2) == 1;
prob.Constraints.con = con;
prob.Objective = x’*A*x;
x0.x = zeros(3,1);
% x0.x = rand(3,1);
show(prob)
[sol,fval,flag,out] = solve(prob,x0)
sol.x
when the initial point is zeres(0),fval is 0,sol.x is [0;0;0].
but when it is rand(3,1),fval is -3.66.
I can’t understand this reason initial point MATLAB Answers — New Questions