not able to execute below query on linux server with mongoDb
mongoexport --db MongoLog --collection dCDMongoLog --query '{$and:[{'jsonObject.responseRaw':{$regex:'<Amount>1000'}},{'jsonObject.createDate':{$gt:'2021-04-01'}},{'jsonObject.createDate':{$lte:'2021-04-08'}}]}' --csv -f jsonObject.mobile,jsonObject.createDate --out /opt/data1234.csv
getting below error
-bash: Amount: No such file or directory
even tried this way :
mongoexport -d MongoLog -c dCDMongoLog -q "{$and:[{'jsonObject.responseRaw':{$regex:'<Amount>1000'}},{'jsonObject.createDate':{$gt:'2021-04-01'}},{'jsonObject.createDate':{$lte:'2021-04-08'}}]}" -f jsonObject.mobile,jsonObject.createDate --type=csv > /opt/data1234.csv
but getting this error:
error validating settings: query '[123 58 91 123 39 106 115 111 110 79 98 106 101 99 116 46 114 101 115 112 111 110 115 101 82 97 119 39 58 123 58 39 60 65 109 111 117 110 116 62 49 48 48 48 39 125 125 44 123 39 106 115 111 110 79 98 106 101 99 116 46 99 114 101 97 116 101 68 97 116 101 39 58 123 58 39 50 48 50 49 45 48 52 45 48 49 39 125 125 44 123 39 106 115 111 110 79 98 106 101 99 116 46 99 114 101 97 116 101 68 97 116 101 39 58 123 58 39 50 48 50 49 45 48 52 45 48 56 39 125 125 93 125]' is not valid JSON: invalid character ':' looking for beginning of object key string
2021-04-16T20:01:00.729-0400 try 'mongoexport --help' for more information
nothing seems to be running. Any other ways?
mongoexport query sucks! it requires single quotes outside and double quotes inside.
below command worked for me.
mongoexport -d MongoLog -c dCDMongoLog -q '{"$and":[{"jsonObject.responseRaw":{$regex:"<Amount>1000"}},{"jsonObject.createDate":{$gt:"2021-04-01"}},{"jsonObject.createDate":{$lte:"2021-04-08"}}]}' -f jsonObject.mobile,jsonObject.createDate --type=csv > /opt/data1235.csv
I have a table object in Matlab with cells as shown in the snapshot:
The cells inside Land and Seamark are as below:
The class of the objects are as below:
>> class(FileData.gTruth.LabelData.Land)
ans =
'cell'
>> class(FileData.gTruth.LabelData.Land{1,1})
ans =
'double'
>> class(FileData.gTruth.LabelData)
ans =
'table'
I tried some syntax like writetable and csvwrite but i am not getting the right format of output. The reading of the Land and Seamark as shown in the figure gets jumbled(reading is columnwise and not row-wise).
I want my output to be in this order:
[1063 126 115 86] [1 169 158 147;1 104 165 66;728 105 276 43;950 113 971 40;1 107 810 23;227 133 48 15;618 131 107 20] [562 220 33 51;1736 167 26 28;532 130 18 15;393 129 23 14]
Code so far:
writetable(FileData.gTruth.LabelData,'labelled1.txt','Delimiter' , ';');
You can simply use reshape on the transpose of the two-dimensional matrices to build a new table:
Ship = [1063 126 115 86]
Land = {[1 169 158 147;1 104 165 66; 728 105 276 43; 950 113 971 40; 1 107 810 23; 227 133 48 15; 618 131 107 20]}
Seamark = {[562 220 33 51; 1736 167 26 28; 532 130 18 15; 393 129 23 14]}
t = table(Ship,Land,Seamark);
t2 = table(t.Ship,reshape(t.Land{:}.',1,[]),reshape(t.Seamark{:}.',1,[]))
writetable(t2,'mycsv.csv','WriteVariableNames',false)
The first and only row of mycsv.csv file is:
1063 126 115 86 1 169 158 147 1 104 165 66 728 105 276 43 950 113 971 40 1 107 810 23 227 133 48 15 618 131 107 20 562 220 33 51 1736 167 26 28 532 130 18 15 393 129 23 14
I used the WriteVariableNames,false Name-Value pair to indicate that the variable names are not to be included in the first row of the file.
I am trying to communicate with a StepRocker motor controller/drive using MATLAB. I have figured out how to format their commands and have been able to get it to move to many of commands. Their commands require that the values be sent in a binary format over RS-232. I started running into some issues and started using an Arduino to echo my commands.
I am currently sending the values 1 - 255 just to test sending bytes over the serial channel. I am sending it to an Arduino and reading the bytes back out of the Arduino. All numbers work except for the numbers between 128 and 159. This is problematic since some of my commands require values in this range.
MATLAB Script:
obj = instrfind; delete(obj); % cleanup any lost objects
clear; close force all; clc; % clear the workspace
sM = serial('COM2','BaudRate',9600, 'Terminator', 'CR', 'Timeout', 10);
fopen(sM);
pause(2); % give port time to open
% make list of numbers 1-255, skip 10/13 since they terminate on the
% arduino
cmd = [1:9 11:12 14:255];
% Send command and get echo
fprintf(sM,cmd);
pause(0.5); % give time for echo
echo = fscanf(sM);
uint8(echo)
fclose(sM);
After executing this script I get the following output:
ans =
Columns 1 through 22
1 2 3 4 5 6 7 8 9 11 12 14 15 16 17 18 19 20 21 22 23 24
Columns 23 through 44
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
Columns 45 through 66
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
Columns 67 through 88
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
Columns 89 through 110
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
Columns 111 through 132
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 63 63 63 63 63 63 63
Columns 133 through 154
63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63
Columns 155 through 176
63 63 63 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
Columns 177 through 198
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
Columns 199 through 220
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
Columns 221 through 242
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
Columns 243 through 254
245 246 247 248 249 250 251 252 253 254 255 13
Looking at the output, you can see that the numbers between 128 and 159 all come through as 63. I am at a loss for what is causing this issue. This is very repeatable, and the problem occurs anytime there is a number in this range, no matter its position in the string, no matter the length of the serial string.
Arduino Code:
bool stringComplete = false;
String inputString = "";
void setup() {
Serial.begin(9600);
}
void loop() {
if (stringComplete) {
Serial.print(inputString);
stringComplete = false;
inputString = "";
}
}
void serialEvent() {
while (Serial.available()) {
char inChar = (char)Serial.read();
inputString += inChar;
if (inChar == '\r') {
stringComplete = true;
}
}
}
Any suggestions or ideas on how to solve this problem?
I have 96 x 96 images, I want to convert each image to pixels and save it to a text file. This is an example of code :
frame = imread('c.jpg');
allpixels = reshape(frame, 96*96, 3)
The Output of the command window is :
a
allpixels =
211 194 176
200 183 163
186 169 143
170 150 123
154 133 104
149 128 99
156 135 106
157 136 109
155 135 110
148 126 102
147 123 97
143 118 88
.....
I want to save only the content of the variable allpixels to a text file. It means the text file should be exactly like this :
211 194 176
200 183 163
186 169 143
170 150 123
154 133 104
149 128 99
156 135 106
157 136 109
155 135 110
148 126 102
147 123 97
143 118 88
I have used :
diary('out.txt');
diary on
But out.txt will contain all the command window output, like this :
a
allpixels =
9216×3 uint8 matrix
211 194 176
200 183 163
186 169 143
170 150 123
154 133 104
149 128 99
156 135 106
157 136 109
155 135 110
148 126 102
147 123 97
143 118 88
How can I do that ?
diary is for activity log of your MATLAB session. To store the specific matrix you can use the following code:
dlmwrite('out.txt', a, 'delimiter', ' ');
See the details here.
I have sample code emulating my actual code. Where I have cell arrays outside the parfor loop. I have to perform computations on strings and numerical outputs will be stored in arrays which I can write to a csv file after each parfor loop. So I made dummy code. But I couldn't get it to execute. The error message is: "subscription mismatch at line 6".
ftemp=fopen('temp.csv','w');
march=cell(1,20);tc=0;
march={'ab' 'cd' 'ef' 'gh' 'ij' 'kl' 'mn' 'op' 'qr' 'st' 'uv' 'AB' 'CD' 'EF' 'GH' 'IJ' 'KL' 'MN' 'OP' 'QR'};
for i=1:10
matlabpool open 4;
parfor j=1:1:20
a(j,1)=randi(200,1,1);
b(j,2)=j+tc;
c(j,3)=march{1,j};
d(j,4)=(randi(200,1,1)/200);
end
fprintf(ftemp,'%d\t%d\t%s\t%f',a,b,c,d);
matlabpool close
clear a b c d;
tc=tc+20;
end
fclose(ftemp);
quit
The cause of the Error is that you are trying to assign a cell into an array in line 9.
I made some changes into your code, they are described in comments.
ftemp=fopen('temp.csv','w');
march=cell(1,20);tc=0;
march={'ab' 'cd' 'ef' 'gh' 'ij' 'kl' 'mn' 'op' 'qr' 'st' 'uv' 'AB' 'CD' 'EF' 'GH' 'IJ' 'KL' 'MN' 'OP' 'QR'};
for i=1:10
parpool local; % here in my version of Matlab 2015 there are no more "matlabpool" if it doesen't work change it back
parfor j=1:20
%i changed variable a(j,1) into a(j) and b(j,2) into b(j): may
%contain empty arrays , idem: for c and d
a(j)=randi(200,1,1);
b(j)=j+tc;
c{j}=march{1,j}; % changed c(j)= march{1,j}; : cause of error
d(j)=randi(200,1,1)/200;
end
fprintf(ftemp,'%d\t%d\t%c\t%d',a,b,char(c),d); % char(c) in order to convert cell array to array of strings
delete(gcp) % there isn't such thing "matlabpool close" , the right expression is "delete(gcp)"
clear a b c d;
tc=tc+20;
end
fclose(ftemp);
%quit : i remove because it closes matlab , please put it back if u really
%want to close matlab after operation
Note: if parpool doesent work for your version of matlab , please change it back to the expression you were using matlabpool open 4;
Well for the unexpected outputs and number of rows in the output , it's because the wrong use of fprintf . We need to print element by element , which means the fprintf has to be inside the parfor loop, so your code should look like this:
ftemp=fopen('temp.csv','w');
march=cell(1,20);tc=0;
march={'ab';'cd';'ef';'gh';'ij';'klm';'mn';'op';'qr';'st';'uv';'ABls';'CD';'E3F';'GH';'IJ';'dynaKL';'MN';'OP';'QR'};
matlabpool open 4;
for k=1:10
%parpool local; % here in my version of Matlab 2015 there are no more "matlabpool" if it doesen't work change it back
parfor j=1:20
%i changed variable a(j,1) into a(j) and b(j,2) into b(j): may
%contain empty arrays , idem: for c and d
a(j)=randi(200,1,1);
b(j)=j+tc;% indexing purposes to identify the order when parallel processing going on
if length(march{j})>2 % this kind of conditions and computations are there in my actual code
c{j}='skip';
else
c{j}=march{j};
end
%d(j)=randi(200,1,1)/200;
fprintf(ftemp,'%d\t%d\t%s\t\n',a(j),b(j),c{j}); % char(c) in order to convert cell array to array of strings
end
clear a b c;
tc=tc+20;
end
fclose(ftemp);
matlabpool close;
the output is:
9 1 ab
171 2 cd
7 3 ef
98 4 gh
102 5 ij
20 6 skip
53 7 mn
174 8 op
36 9 qr
30 10 st
130 11 uv
127 12 skip
133 13 CD
65 14 skip
118 15 GH
130 16 IJ
139 17 skip
168 18 MN
57 19 OP
25 20 QR
22 21 ab
39 22 cd
83 23 ef
22 24 gh
159 25 ij
40 26 skip
164 27 mn
78 28 op
194 29 qr
88 30 st
125 31 uv
1 32 skip
2 33 CD
112 34 skip
161 35 GH
170 36 IJ
55 37 skip
59 38 MN
18 39 OP
134 40 QR
80 41 ab
118 42 cd
108 43 ef
174 44 gh
97 45 ij
157 46 skip
85 47 mn
98 48 op
40 49 qr
11 50 st
171 51 uv
139 52 skip
90 53 CD
70 54 skip
173 55 GH
150 56 IJ
186 57 skip
155 58 MN
136 59 OP
96 60 QR
158 61 ab
118 62 cd
124 63 ef
127 64 gh
26 65 ij
124 66 skip
91 67 mn
186 68 op
63 69 qr
137 70 st
170 71 uv
98 72 skip
132 73 CD
80 74 skip
160 75 GH
20 76 IJ
156 77 skip
142 78 MN
110 79 OP
51 80 QR
18 81 ab
29 82 cd
40 83 ef
49 84 gh
102 85 ij
113 86 skip
96 87 mn
44 88 op
166 89 qr
90 90 st
21 91 uv
60 92 skip
44 93 CD
166 94 skip
103 95 GH
123 96 IJ
77 97 skip
163 98 MN
138 99 OP
111 100 QR
94 101 ab
133 102 cd
158 103 ef
13 104 gh
26 105 ij
117 106 skip
90 107 mn
58 108 op
156 109 qr
79 110 st
196 111 uv
168 112 skip
192 113 CD
160 114 skip
56 115 GH
129 116 IJ
191 117 skip
157 118 MN
170 119 OP
30 120 QR
137 121 ab
128 122 cd
12 123 ef
38 124 gh
38 125 ij
122 126 skip
97 127 mn
129 128 op
142 129 qr
154 130 st
99 131 uv
85 132 skip
129 133 CD
111 134 skip
108 135 GH
78 136 IJ
102 137 skip
48 138 MN
100 139 OP
89 140 QR
114 141 ab
12 142 cd
184 143 ef
145 144 gh
5 145 ij
48 146 skip
92 147 mn
64 148 op
87 149 qr
32 150 st
136 151 uv
103 152 skip
90 153 CD
73 154 skip
28 155 GH
191 156 IJ
63 157 skip
120 158 MN
104 159 OP
178 160 QR
148 161 ab
36 162 cd
129 163 ef
11 164 gh
172 165 ij
186 166 skip
145 167 mn
142 168 op
150 169 qr
185 170 st
14 171 uv
141 172 skip
22 173 CD
163 174 skip
48 175 GH
164 176 IJ
117 177 skip
25 178 MN
110 179 OP
111 180 QR
175 181 ab
60 182 cd
195 183 ef
44 184 gh
163 185 ij
4 186 skip
103 187 mn
95 188 op
127 189 qr
10 190 st
11 191 uv
182 192 skip
162 193 CD
179 194 skip
76 195 GH
104 196 IJ
153 197 skip
103 198 MN
4 199 OP
154 200 QR
Also the output has 200 rows.
ftemp=fopen('temp.csv','w');
march=cell(1,20);tc=0;
march={'ab';'cd';'ef';'gh';'ij';'klm';'mn';'op';'qr';'st';'uv';'ABls';'CD';'E3F';'GH';'IJ';'dynaKL';'MN';'OP';'QR'};
matlabpool open 4;
for k=1:10
%parpool local; % here in my version of Matlab 2015 there are no more "matlabpool" if it doesen't work change it back
parfor j=1:20
%i changed variable a(j,1) into a(j) and b(j,2) into b(j): may
%contain empty arrays , idem: for c and d
a(j)=randi(200,1,1);
b(j)=j+tc;% indexing purposes to identify the order when parallel processing going on
if length(march{j})>2 % this kind of conditions and computations are there in my actual code
c{j}='skip';
else
c{j}=march{j};
end
%d(j)=randi(200,1,1)/200;
end
fprintf(ftemp,'%d\t%d\t%s\n',a,b,c{:}); % char(c) in order to convert cell array to array of strings
clear a b c;
tc=tc+20;
end
fclose(ftemp);
matlabpool close;
but the output of the program i coudlnt get it
130 127 Abf5ȱ3³]À#¾
1 2
97 98 cd
101 102 gh
105 106 skip
109 110 op
113 114 st
117 118 skip
67 68 skip
71 72 IJ
115 107 ip
77 78 OP
81 82 168 57 ®$ «E�,vp|}¤
21 22 !"#$%&'(
97 98 cd
101 102 gh
105 106 skip
109 110 op
113 114 st
117 118 skip
67 68 skip
71 72 IJ
115 107 ip
77 78 OP
81 82 88 125 S([g 0'0Â"
41 42 +,-./0123456789:;<
97 98 cd
101 102 gh
105 106 skip
109 110 op
113 114 st
117 118 skip
67 68 skip
71 72 IJ
115 107 ip
77 78 OP
81 82 161 170 7Na�U;6´q¶nl®v¤
61 62 ?#ABCDEFGHIJKLMNOP
97 98 cd
101 102 gh
105 106 skip
109 110 op
113 114 st
117 118 skip
67 68 skip
71 72 IJ
115 107 ip
77 78 OP
81 82 171 139 ZFºPµ~R(`b[
81 82 STUVWXYZ[\]^_`abcd
97 98 cd
101 102 gh
105 106 skip
109 110 op
113 114 st
117 118 skip
67 68 skip
71 72 IJ
115 107 ip
77 78 OP
81 82 132 80 ||£)Á1[ªavb-
101 102 ghijklmnopqrstuvwx
97 98 cd
101 102 gh
105 106 skip
109 110 op
113 114 st
117 118 skip
67 68 skip
71 72 IJ
115 107 ip
77 78 OP
81 82 186 63 ª`neepw»fq°r1
121 122 {|}~�
97 98 cd
101 102 gh
105 106 skip
109 110 op
113 114 st
117 118 skip
67 68 skip
71 72 IJ
115 107 ip
77 78 OP
81 82 51 160 M(1´uOAF¦{¬©
141 142 ���
97 98 cd
101 102 gh
105 106 skip
109 110 op
113 114 st
117 118 skip
67 68 skip
71 72 IJ
115 107 ip
77 78 OP
81 82 90 21 <,uZgh�lu¨B,¦
0
161 162 £¤¥¦§¨©ª«¬®¯°±²³´
97 98 cd
101 102 gh
105 106 skip
109 110 op
113 114 st
117 118 skip
67 68 skip
71 72 IJ
115 107 ip
77 78 OP
81 82 192 160 o£¿^hyµÄ¨�Ä�O
181 182 ·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈ
97 98 cd
101 102 gh
105 106 skip
109 110 op
113 114 st
117 118 skip
67 68 skip
71 72 IJ
115 107 ip
77 78 OP
81 82
i mean to say why only 124 iterations took place instead of 200. and why these arbitrary outputs are there in the 3rd column