Repeating replacements in a row
Show older comments
I’m having one final problem where I need to read in different rows of a table and replace specific values in each row with corresponding values in another table. so values 999 in Row A in table 1 need to be replaced by the first value in table 2 (Table 2 is just 1 Column of numbers),then 999 values in Row B in table 1 need to be replaced by value 2 in table 2.
I’m having a lot of difficulty with this, do you have any suggestions?
9 Comments
Rik
on 16 Jan 2018
Is your variable a matrix or of the actual datatype table?
Matt Brianik
on 16 Jan 2018
"i used the isnan o change all values of nan to a value of 999 so that i have all numbers to work with"
That is a bad idea (and a waste of time). NaN is a better indicator of a missing value than an arbitrary number. The functions ismissing, fillmissing and a few others won't work with your non-standard indicator.
"I plan to make each row variable a small decimal like 0.0001 and 0.0002 which will then correspond to another table where i will replace all 0.0001"
Again, that sounds like a bad idea and a waste of time. Just use the values as they are. At the very least use integers.
A better description of what you're trying to achieve, in particular the overarching goal, and some numerical examples (using valid matlab syntax) would be very useful. Then we could suggest some better way of achieving that ultimate goal.
Stephen23
on 16 Jan 2018
My company receives data tables with sampling location (monitoring wells) and a list of compounds detected at each specific well. If a certain compound wasn't detected, the result will Read N.D. for no detect. I have to take this data table and change all the N.D. to show less than the standard for the particular compound. for example if acetone levels for wells 1 2 and 3 were 10,N.D., 17, i would have to make the new spreadsheet read 10, <6,17. because the limit for detection of acetone is 6.
I have to do this for hundreds of compounds in dozens of wells, where each compound has a different limit value.
Stephen23
on 16 Jan 2018
"I’m having a lot of difficulty with this"
Yes, implementing this would be difficult. Using NaN's would be much simpler because they are processed without you having to do anything at all.
Matt Brianik
on 16 Jan 2018
Guillaume
on 16 Jan 2018
Is the question then on using matlab to edit some files? If so, an example file would be useful. If not, and you want to import the file for further processing in matlab, then converting numeric data into text also sounds like a bad idea.
In general just use indexing:
M(isnan(M)) = somelimitvalue
You might need to apply this to just one column, or otherwise tailor it to however your data is arranged.
Stephen23
on 16 Jan 2018
here is a sample file, i have my code reading in
here is what i have been doing so far code wise
clear
close all
CHOSEN_FILE='Sample_File.csv';
Table_Data = xlsread(CHOSEN_FILE);
% Table_Data(isnan(Table_Data))=999999;
Table_Labels = readtable(CHOSEN_FILE);
[Initial_CellCount_Rows,HH]= size(Table_Data);
Well_Data = Table_Data(4:Initial_CellCount_Rows,1:3:end)
Well_Labels= Table_Labels(2,5:3:end);
Well_Labels= table2cell(Well_Labels);
[CellCount_Row,CellCount_Collum] = size(Well_Data);
Number_of_Wells=CellCount_Collum;
Number_of_Compounds=(CellCount_Row);
Answers (0)
Categories
Find more on Tables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!