我有几个主题需要生成一个图,因为我有很多主题,我希望在一页中包含多个图,而不是一个主题图。这是我到目前为止所做的:
读取带有主题名称的txt文件
subjs <- scan ("ListSubjs.txt", what = "")
Run Code Online (Sandbox Code Playgroud)
创建一个列表来保存绘图对象
pltList <- list()
for(s in 1:length(subjs))
{
setwd(file.path("C:/Users/", subjs[[s]])) #load subj directory
ifile=paste("Co","data.txt",sep="",collapse=NULL) #Read subj file
dat = read.table(ifile)
dat <- unlist(dat, use.names = FALSE) #make dat usable for ggplot2
df <- data.frame(dat)
pltList[[s]]<- print(ggplot( df, aes(x=dat)) + #save each plot with unique name
geom_histogram(binwidth=.01, colour="cyan", fill="cyan") +
geom_vline(aes(xintercept=0), # Ignore NA values for mean
color="red", linetype="dashed", size=1)+
xlab(paste("Co_data", subjs[[s]] , sep=" ",collapse=NULL)))
}
Run Code Online (Sandbox Code Playgroud)
在这一点上,我可以显示单个图,例如
print (pltList[1]) #will print first …Run Code Online (Sandbox Code Playgroud) 我需要随机生成固定数量的非重叠圆。我可以用这段代码随机显示圆圈,在这种情况下是 20 个,
for i =1:20
x=0 + (5+5)*rand(1)
y=0 + (5+5)*rand(1)
r=0.5
circle3(x,y,r)
hold on
end
Run Code Online (Sandbox Code Playgroud)
但是圆圈重叠,我想避免这种情况。这是以前使用 Mathematica 的用户实现的https://mathematica.stackexchange.com/questions/69649/generate-nonoverlapping-random-circles,但我正在使用 MATLAB,我想坚持下去。
为了重现性,这是函数,circle3,我用来绘制圆圈
function h = circle3(x,y,r)
d = r*2;
px = x-r;
py = y-r;
h = rectangle('Position',[px py d d],'Curvature',[1,1]);
daspect([1,1,1])
Run Code Online (Sandbox Code Playgroud)
谢谢你。
我正在使用 ezANOVA 来实现对具有受试者内变量和受试者间变量的实验设计的分析。我成功实施了 ezANOVA,如下所示:
structure(list(Sub = structure(c(3L, 3L, 3L, 4L, 4L, 4L, 1L,
1L, 1L, 2L, 2L, 2L), .Label = c("A7011", "A7022", "B13", "B14"
), class = "factor"), Depvariable = c(0.375, 0.066667, 0.15,
0.275, 0.025, 0.78333, 0.24167, 0.058333, 0.14167, 0.19167, 0.5,
0), Group = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L,
1L, 1L), .Label = c("A", "B"), class = "factor"), WithinFactor = c(0.6,
0, -0.3, 0.6, 0, -0.3, 0.6, 0, -0.3, 0.6, 0, -0.3)), .Names = c("Sub", …Run Code Online (Sandbox Code Playgroud) 我在MATLAB中有一组数字,例如,
a = [1 1 1; 2 2 1; 3 3 2; 4 5 1];
Run Code Online (Sandbox Code Playgroud)
我想用字符串替换数字.
例如,1 ="苹果"; 2 ="你好"; 3 ="再见";
我可以用其他数字代替,例如,
a(a==1) = 999
a(a==2) = 998
Run Code Online (Sandbox Code Playgroud)
但我需要通过替换字符串来完成同样的事情.对我来说不容易有人帮助我吗?谢谢,马蒂尔德