I have a text file containing special characters, text and some numbers and I need to extract from it some values which appear every n-th row. Since the file has around 20k rows, I want the algorithm to find first and next rows. I've read text file to matrix with readdlm(), but the type of array is ANY, and findfirst() gives and error "access to undefined reference". Could you give me some guidance, please?
Regards
Mike
#Jubobs Here is results file :
https://copy.com/i9GeXhK0qHdfwpkT
I need to extract values for node 79 , which starts at row 10
So i want the algorithm to find the row file[10,1] and get the value file[10,2], and then next and so on.
file=readdlm("results.txt")
findfirst(file,"79")
access to undefined reference
while loading In[13], in expression starting on line 1
in findnext at array.jl:1034 (repeats 2 times)
Best bet would be to read the file as a string and search through it using a regex (or manually if you prefer). It doesn't make much sense to open your txt file as a delimited one (probably that's where your error stems from). Instead, do the following:
f = open("results.txt") # f <: some kind of IO object
data = readall(f) # data <: AbstractString
close(f)
I hope this helps.
Related
I am trying to create a new reference containing another reference as in ${var${randnum}}.
Ultimately, I want to create a variable which refers to a two times two randomized set of variables.
As the above approach did not work, I developed it further with below result.
In the calculate field I write
concat('$','{','trust',${rand_no2},'_' ,${rand_no3_1},'}')
Which should result in
${trust1_1}
and respective combinations.
Without line 11 (name=ref2) the file compiles and I can start it in ODK Collect (v.2.4) on my phone. When I reach line 10 (in ODK Collect), however, I receive the message:
"Error Occured
Dependency cycle in s; recursion limit exceeded!!"
(I included line 11 to show what I want to do in the end.)
I am writing the file in Excel and compile it with ODK xlsform offline. (For testing I transfer it via cable to my phone.)
The xls file for reproduction can be found here:
https://forum.getodk.org/t/concatenate-references-to-create-new-reference-var-randnum/34968
Thank you very much in advance!
You're mixing up some things related to the ${q} syntax, question names and question values.
Note that ODK Collect does not actually understand the ${q} syntax (which is XLSForm-only). It's helpful to look at the actual form format that ODK collect understands which is called XForm, an XML format that XLSForm converts into. However, even if ODK Collect understood the ${q} syntax, your approach still wouldn't work since you're creating a string value for the ref question (using concat). This wouldn't magically be evaluated as a reference / formula. You cannot dynamically create a reference or formula.
At the moment (until ODK supports something like the local-name() function), maybe the best approach is to use position and put the calculated values inside a group. Something like //group/calc[number(${pos})] perhaps. Note that positions are 1-based (so the first item is position 1) and casting the position to a number or integer is required.
I am new to Python and am over complicating the coding on a project so I am starting with much smaller data sets in order to learn the process. My boss is having me compare two CSV files. The first CSV only contains the data 1,2,3,4,5,6 all in a single column. He wants me to set this CSV file as an array so I can compare the second CSV against it. The second CSV contains the data 3,5,6 all in a single column. The code should result in a print out of 1,2,4 as it is the only data not found in both CSV files.
I originally tried to write a code to import both CSV files and compare data without setting it as an array but this did not work so the first CSV file needs to be set as an array. The problem is I am not sure exactly how to do this with an array. This is what I have so far, any help anyone could give me would be greatly appreciated. I have been working on this project for a week now and am at a total loss, even with this simplified form.
import csv
temp_list = []
with open('1.csv','rb') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
for row in reader:
In terms of psuedo-code, what you need to do here is import both csv files into two separate arrays, Array A and Array B for example.
Now what you need to do is compare each index position in one array, to each index position in the other array.
You need to create a nested loop, where the outer loop will choose an index position in A and then inner loop chooses a position in B.
After you check one index in A with each position in B, and no positions are the same, I suggest adding this value into a third array, C. You can check which positions are the same by using a boolean flag. When your code is done, C will have any values that don't exist in both A and B.
I suggest following these tutorials to learn more about python syntax:
https://www.w3schools.com/python/
Good luck
I am newer to programming and I am trying to figure out how I can add all of the numbers from the B column together and all of the C column together and the D column together with those variables named x y and z respectively. I have been searching everywhere for an answer. All I have gotten is to read the first line of the csv file.
This is a screenshot of part of the CSV file:
Once you've read it in, you need to somehow split it up into actual columns. Check this function, that should help.
strtok()
Then you need to store it in some kind of array. Then index which elements in the array you want, and process them by using a cumulative sum. This might require a while loop until you've reached the last line of the file.
I will leave the actual code to you, but this should get you going.
I am supposed to integrate data of acceleration and time to get velocity using a user defined script.
What I have so far is:
function myIntegral=myCumulativeTrapz(X,Y)
myIntegral=0.5*(Y+(Y+1))*((X+1)-X)
When I hit run, I get this error:
Error: File: myCumulativeTrapz.m Line: 27 Column: 1
Function definitions are not permitted in this context.
If the script for integration was successful, I would then put
velocity=myCumulativeTrapz(data_resultant_acc(:,1), data_resultant_acc(:,2))
in the command window. (Data_resultant_acc is an array where time is in the first column and acceleration is in the second column.)
Can someone help me out and tell me why is this not working?
The error message is shown because Matlab file can't contain both functions and commands that are outside of any functions. So, if you have something like
data_resultant_acc = rand(10,2);
velocity=myCumulativeTrapz(data_resultant_acc(:,1), data_resultant_acc(:,2));
function myIntegral=myCumulativeTrapz(X,Y)
myIntegral=0.5*(Y+(Y+1))*((X+1)-X)
end
change that to
function myProject
data_resultant_acc = rand(10,2);
velocity=myCumulativeTrapz(data_resultant_acc(:,1), data_resultant_acc(:,2));
end
function myIntegral=myCumulativeTrapz(X,Y)
myIntegral=0.5*(Y+(Y+1))*((X+1)-X)
end
thus making myProject the top-level function that will be executed when you run the file (for best results, the file name should be the name of that function).
After that, you will discover that 0.5*(Y+(Y+1))*((X+1)-X) is not a valid formula, for multiple reasons. Since both X and Y are column vectors, the first one should be transposed before multiplication. Also, you are adding 1 to vector components instead of shifting index by 1. A correct way to do the index shift is below:
myIntegral=0.5*(Y(1:end-1)+Y(2:end))'*(X(2:end)-X(1:end-1));
Here the comma selectors create vectors that omit either the very first or the very last entry. The average of two such vectors gives the averages of adjacent values. The difference gives the difference of adjacent values.
I am trying to use Weka for text classification.
For this purpose, it makes sense to use the sparse ARFF data file format.
Using Weka 3.7.2, I tried:
Transforming a text directory to an Instances object using
TextDirectoryLoader.
Translating the strings resulting from the former stage to numbers using StringToWordVector.
The first stage worked fine. The second stage caused a problem, described this way in the
Weka's ARFF file format specification:
Warning: There is a known problem saving SparseInstance objects from datasets that have string attributes. In Weka, string and nominal data values are stored as numbers; these numbers act as indexes into an array of possible attribute values (this is very efficient). However, the first string value is assigned index 0: this means that, internally, this value is stored as a 0. When a SparseInstance is written, string instances with internal value 0 are not output, so their string value is lost (and when the arff file is read again, the default value 0 is the index of a different string value, so the attribute value appears to change).
The ARFF format suggests this solution:
To get around this problem, add a dummy string value at index 0 that is never used whenever you declare string attributes that are likely to be used in SparseInstance objects and saved as Sparse ARFF files.
I am trying to do just that - add a dummy string. I have failed to do this manually (by editing the ARFF file). Can anyone who has done this already post an example - either of a program segment doing this, a properly modified ARFF file, or some other way to do this?
Thanks.
Do NOT edit the arff file directly.
I just answered a similar question here:
Weka printing sparse arff file
Use the same code example.