MATLAB Randomly Changes Values in Array to Scientific Notation

I have a script that reads inputs from an excel file, then stores specific arrays that I need, as different variables.
These will later need to be written to an output txt file along with other strings (this output needs to be a specific format so it can feed an executable).
My problem is that when I read the data from the excel file, MATLAB keeps changing only two of the values to scientific notation.
My code is structured like so:
DATAINEED = readtable(fullfile(input_location,filename));
array1 = unique(DATAINEED.array1);
array2 = unique(DATAINEED.array2);
My problem is MATLAB then stores "array1" like so when I open the variable:
1000
2000
3000
4e+03
5000
6e+03
If I type "array1" in the command window, it prints out just fine (1000, 2000, 3000, 4000…etc.)
The problem is, if I try to print the variable along with another string so it can feed into the text file, it keeps that weird scientific notation for the couple of values.
I’m using the following code:
OutputRow1 = "array1 has: "+sprintf(‘%d ‘,array1’);

This results in:
OutputRow1 =
"array1 has: 1000 2000 3000 4e+03 5000 6e+03"
Array 2 is completely fine (also an array of numbers, but not in the thousands). I’ve tried format short g and long g, doesn’t help. Wondering if anyone has any insights, suggestions or other ways to accomplish what I need.I have a script that reads inputs from an excel file, then stores specific arrays that I need, as different variables.
These will later need to be written to an output txt file along with other strings (this output needs to be a specific format so it can feed an executable).
My problem is that when I read the data from the excel file, MATLAB keeps changing only two of the values to scientific notation.
My code is structured like so:
DATAINEED = readtable(fullfile(input_location,filename));
array1 = unique(DATAINEED.array1);
array2 = unique(DATAINEED.array2);
My problem is MATLAB then stores "array1" like so when I open the variable:
1000
2000
3000
4e+03
5000
6e+03
If I type "array1" in the command window, it prints out just fine (1000, 2000, 3000, 4000…etc.)
The problem is, if I try to print the variable along with another string so it can feed into the text file, it keeps that weird scientific notation for the couple of values.
I’m using the following code:
OutputRow1 = "array1 has: "+sprintf(‘%d ‘,array1’);

This results in:
OutputRow1 =
"array1 has: 1000 2000 3000 4e+03 5000 6e+03"
Array 2 is completely fine (also an array of numbers, but not in the thousands). I’ve tried format short g and long g, doesn’t help. Wondering if anyone has any insights, suggestions or other ways to accomplish what I need. I have a script that reads inputs from an excel file, then stores specific arrays that I need, as different variables.
These will later need to be written to an output txt file along with other strings (this output needs to be a specific format so it can feed an executable).
My problem is that when I read the data from the excel file, MATLAB keeps changing only two of the values to scientific notation.
My code is structured like so:
DATAINEED = readtable(fullfile(input_location,filename));
array1 = unique(DATAINEED.array1);
array2 = unique(DATAINEED.array2);
My problem is MATLAB then stores "array1" like so when I open the variable:
1000
2000
3000
4e+03
5000
6e+03
If I type "array1" in the command window, it prints out just fine (1000, 2000, 3000, 4000…etc.)
The problem is, if I try to print the variable along with another string so it can feed into the text file, it keeps that weird scientific notation for the couple of values.
I’m using the following code:
OutputRow1 = "array1 has: "+sprintf(‘%d ‘,array1’);

This results in:
OutputRow1 =
"array1 has: 1000 2000 3000 4e+03 5000 6e+03"
Array 2 is completely fine (also an array of numbers, but not in the thousands). I’ve tried format short g and long g, doesn’t help. Wondering if anyone has any insights, suggestions or other ways to accomplish what I need. array, scientific notation, matlab, sprintf, storing variables, double MATLAB Answers — New Questions

​

Leave a Reply

Your email address will not be published. Required fields are marked *